Module: Brainstem::Concerns::PresenterDSL::ClassMethods
- Defined in:
- lib/brainstem/concerns/presenter_dsl.rb
Instance Method Summary collapse
- #associations(&block) ⇒ Object
- #brainstem_key(key) ⇒ Object
- #conditionals(&block) ⇒ Object
- #default_sort_order(sort_string = nil) ⇒ Object
- #deprecated_type_warning ⇒ Object
- #description(str, options = { nodoc: false }) ⇒ Object
-
#documented! ⇒ Object
Temporary implementation to track controllers that have been documented.
- #fields(&block) ⇒ Object
- #filter(name, type = DEFAULT_FILTER_DATA_TYPE, options = {}, &block) ⇒ Object
-
#helper(mod = nil, &block) ⇒ Object
Declare a helper module or block whose methods will be available in dynamic fields and associations.
- #nodoc! ⇒ Object
- #preload(*args) ⇒ Object
- #query_strategy(strategy) ⇒ Object
- #reset_configuration! ⇒ Object private
- #search(&block) ⇒ Object
- #sort_order(name, *args, &block) ⇒ Object
- #title(str, options = { nodoc: false }) ⇒ Object
Instance Method Details
#associations(&block) ⇒ Object
39 40 41 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 39 def associations(&block) AssociationsBlock.new(configuration, &block) end |
#brainstem_key(key) ⇒ Object
168 169 170 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 168 def brainstem_key(key) configuration[:brainstem_key] = key.to_s end |
#conditionals(&block) ⇒ Object
31 32 33 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 31 def conditionals(&block) ConditionalsBlock.new(configuration, &block) end |
#default_sort_order(sort_string) ⇒ String #default_sort_order ⇒ String
84 85 86 87 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 84 def default_sort_order(sort_string = nil) configuration[:default_sort_order] = sort_string if sort_string configuration[:default_sort_order] end |
#deprecated_type_warning ⇒ Object
193 194 195 196 197 198 199 200 201 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 193 def deprecated_type_warning ActiveSupport::Deprecation.warn( 'Please specify the `type` of the filter as the second argument. If not specified, '\ 'it will default to `:string`. This default behavior will be deprecated in the next major '\ 'version and will need to be explicitly specified. '\ 'e.g. `filter :status, :string, items: ["Started", "Completed"]`', caller ) end |
#description(str, options = { nodoc: false }) ⇒ Object
47 48 49 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 47 def description(str, = { nodoc: false }) configuration[:description] = .merge(info: str) end |
#documented! ⇒ Object
Temporary implementation to track controllers that have been documented.
58 59 60 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 58 def documented! configuration[:documented] = true end |
#fields(&block) ⇒ Object
35 36 37 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 35 def fields(&block) FieldsBlock.new(configuration[:fields], &block) end |
#filter(name, type, options = {}) ⇒ Object #filter(name, type, options = {}) {|scope, arg| ... } ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 145 def filter(name, type = DEFAULT_FILTER_DATA_TYPE, = {}, &block) if type.is_a?(Hash) = type if .blank? type = DEFAULT_FILTER_DATA_TYPE deprecated_type_warning elsif type.to_s == 'array' [:item_type] = [:item_type].to_s.presence || DEFAULT_FILTER_DATA_TYPE end = %w(default info include_params nodoc items item_type) .select! { |k, v| .include?(k.to_s) } configuration[:filters][name] = .merge({ value: (block_given? ? block : nil), type: type.to_s, }) end |
#helper(mod = nil, &block) ⇒ Object
Declare a helper module or block whose methods will be available in dynamic fields and associations.
63 64 65 66 67 68 69 70 71 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 63 def helper(mod = nil, &block) if mod configuration[:helpers] << mod end if block configuration[:helpers] << Module.new.tap { |mod| mod.module_eval(&block) } end end |
#nodoc! ⇒ Object
51 52 53 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 51 def nodoc! configuration[:nodoc] = true end |
#preload(*args) ⇒ Object
27 28 29 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 27 def preload(*args) configuration.array!(:preloads).concat args end |
#query_strategy(strategy) ⇒ Object
172 173 174 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 172 def query_strategy(strategy) configuration[:query_strategy] = strategy end |
#reset_configuration! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 177 def reset_configuration! configuration.array!(:preloads) configuration.array!(:helpers) configuration.nest!(:conditionals) configuration.nest!(:fields) configuration.nest!(:filters) configuration.nest!(:sort_orders) configuration.nest!(:associations) configuration.nonheritable!(:title) configuration.nonheritable!(:description) configuration.nonheritable!(:nodoc) end |
#search(&block) ⇒ Object
164 165 166 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 164 def search(&block) configuration[:search] = block end |
#sort_order(name, order, options) ⇒ Object #sort_order(name, options) {|scope| ... } ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 112 def sort_order(name, *args, &block) = %w(info nodoc) = args. .select { |k, v| .include?(k.to_s) } order = args.first raise ArgumentError, "A sort order must be given" unless block_given? || order configuration[:sort_orders][name] = .merge({ value: (block_given? ? block : order) }) end |
#title(str, options = { nodoc: false }) ⇒ Object
43 44 45 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 43 def title(str, = { nodoc: false }) configuration[:title] = .merge(info: str) end |