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 }) ⇒ Object
- #fields(&block) ⇒ Object
- #filter(name, 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
37 38 39 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 37 def associations(&block) AssociationsBlock.new(configuration, &block) end |
#brainstem_key(key) ⇒ Object
148 149 150 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 148 def brainstem_key(key) configuration[:brainstem_key] = key.to_s end |
#conditionals(&block) ⇒ Object
29 30 31 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 29 def conditionals(&block) ConditionalsBlock.new(configuration, &block) end |
#default_sort_order(sort_string) ⇒ String #default_sort_order ⇒ String
75 76 77 78 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 75 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 }) ⇒ Object
45 46 47 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 45 def description(str, = { nodoc: false }) configuration[:description] = .merge(info: str) end |
#fields(&block) ⇒ Object
33 34 35 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 33 def fields(&block) FieldsBlock.new(configuration[:fields], &block) end |
#filter(name, options = {}) ⇒ Object #filter(name, options = {}) {|scope, arg| ... } ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 134 def filter(name, = {}, &block) = %w(default info include_params nodoc) .select! { |k, v| .include?(k.to_s) } configuration[:filters][name] = .merge({ value: (block_given? ? block : nil) }) end |
#helper(mod = nil, &block) ⇒ Object
Declare a helper module or block whose methods will be available in dynamic fields and associations.
54 55 56 57 58 59 60 61 62 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 54 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
49 50 51 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 49 def nodoc! configuration[:nodoc] = true end |
#preload(*args) ⇒ Object
25 26 27 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 25 def preload(*args) configuration.array!(:preloads).concat args end |
#query_strategy(strategy) ⇒ Object
152 153 154 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 152 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.
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 157 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
144 145 146 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 144 def search(&block) configuration[:search] = block end |
#sort_order(name, order, options) ⇒ Object #sort_order(name, options) {|scope| ... } ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 103 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
41 42 43 |
# File 'lib/brainstem/concerns/presenter_dsl.rb', line 41 def title(str, = { nodoc: false }) configuration[:title] = .merge(info: str) end |