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
- #description(str, options = { nodoc: false, internal: false }) ⇒ Object
-
#documented! ⇒ Object
Temporary implementation to track controllers that have been documented.
- #fields(&block) ⇒ Object
- #filter(name, 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.
- #internal!(description = true) ⇒ Object
- #nodoc!(description = true) ⇒ 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, internal: false }) ⇒ Object
Instance Method Details
#associations(&block) ⇒ Object
38 39 40 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 38 def associations(&block) AssociationsBlock.new(configuration, &block) end |
#brainstem_key(key) ⇒ Object
167 168 169 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 167 def brainstem_key(key) configuration[:brainstem_key] = key.to_s end |
#conditionals(&block) ⇒ Object
30 31 32 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 30 def conditionals(&block) ConditionalsBlock.new(configuration, &block) end |
#default_sort_order(sort_string) ⇒ String #default_sort_order ⇒ String
86 87 88 89 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 86 def default_sort_order(sort_string = nil) configuration[:default_sort_order] = sort_string if sort_string configuration[:default_sort_order] end |
#description(str, options = { nodoc: false, internal: false }) ⇒ Object
46 47 48 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 46 def description(str, = { nodoc: false, internal: false }) configuration[:description] = .merge(info: str) end |
#documented! ⇒ Object
Temporary implementation to track controllers that have been documented.
61 62 63 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 61 def documented! configuration[:documented] = true end |
#fields(&block) ⇒ Object
34 35 36 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 34 def fields(&block) FieldsBlock.new(configuration[:fields], &block) end |
#filter(name, type, options = {}) ⇒ Object #filter(name, type, options = {}) {|scope, arg| ... } ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 149 def filter(name, type, = {}, &block) if 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.
66 67 68 69 70 71 72 73 74 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 66 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 |
#internal!(description = true) ⇒ Object
54 55 56 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 54 def internal!(description = true) configuration[:internal] = description end |
#nodoc!(description = true) ⇒ Object
50 51 52 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 50 def nodoc!(description = true) configuration[:nodoc] = description end |
#preload(*args) ⇒ Object
26 27 28 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 26 def preload(*args) configuration.array!(:preloads).concat args end |
#query_strategy(strategy) ⇒ Object
171 172 173 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 171 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.
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 176 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
163 164 165 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 163 def search(&block) configuration[:search] = block end |
#sort_order(name, order, options) ⇒ Object #sort_order(name, options) {|scope| ... } ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 115 def sort_order(name, *args, &block) = %w(info nodoc internal direction) = args. .select { |k, v| .include?(k.to_s) } .with_indifferent_access [:direction] = true unless .has_key?(:direction) 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, internal: false }) ⇒ Object
42 43 44 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 42 def title(str, = { nodoc: false, internal: false }) configuration[:title] = .merge(info: str) end |