Class: Brainstem::DSL::BlockField
- Defined in:
- lib/brainstem/dsl/block_field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Attributes inherited from Field
#conditionals, #name, #options, #type
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #evaluate_value_on(model, context, helper_instance = Object.new) ⇒ Object
-
#initialize(name, type, options, parent_field = nil) ⇒ BlockField
constructor
A new instance of BlockField.
- #run_on(model, context, helper_instance = Object.new) ⇒ Object
- #use_parent_value?(field) ⇒ Boolean
Methods inherited from Field
#conditional?, #conditionals_match?, #description, #method_name, #optional?, #optioned?, #presentable?
Methods included from Concerns::Lookup
#key_for_lookup, #run_on_with_lookup
Constructor Details
#initialize(name, type, options, parent_field = nil) ⇒ BlockField
Returns a new instance of BlockField.
11 12 13 14 |
# File 'lib/brainstem/dsl/block_field.rb', line 11 def initialize(name, type, , parent_field = nil) super(name, type, ) @parent_field = parent_field end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
7 8 9 |
# File 'lib/brainstem/dsl/block_field.rb', line 7 def configuration @configuration end |
Class Method Details
.for(name, type, options, parent_field = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/brainstem/dsl/block_field.rb', line 34 def self.for(name, type, , parent_field = nil) case type.to_s when 'array' DSL::ArrayBlockField.new(name, type, , parent_field) when 'hash' DSL::HashBlockField.new(name, type, , parent_field) else raise "Unknown Brainstem Block Field type encountered: #{type}" end end |
Instance Method Details
#[](key) ⇒ Object
26 27 28 |
# File 'lib/brainstem/dsl/block_field.rb', line 26 def [](key) configuration[key] end |
#evaluate_value_on(model, context, helper_instance = Object.new) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/brainstem/dsl/block_field.rb', line 45 def evaluate_value_on(model, context, helper_instance = Object.new) if [:lookup] run_on_with_lookup(model, context, helper_instance) elsif [:dynamic] proc = [:dynamic] if proc.arity == 1 helper_instance.instance_exec(model, &proc) else helper_instance.instance_exec(&proc) end elsif [:via] model.send([:via]) else raise "Block field #{name} can only be evaluated if :dynamic, :lookup, :via options are specified." end end |
#run_on(model, context, helper_instance = Object.new) ⇒ Object
30 31 32 |
# File 'lib/brainstem/dsl/block_field.rb', line 30 def run_on(model, context, helper_instance = Object.new) raise NotImplementedError.new("Override this method in a sub class") end |
#use_parent_value?(field) ⇒ Boolean
62 63 64 65 66 |
# File 'lib/brainstem/dsl/block_field.rb', line 62 def use_parent_value?(field) return true unless field..has_key?(:use_parent_value) field.[:use_parent_value] end |