Class: Brainstem::DSL::Association
- Inherits:
-
Object
- Object
- Brainstem::DSL::Association
- Includes:
- Concerns::Lookup
- Defined in:
- lib/brainstem/dsl/association.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target_class ⇒ Object
readonly
Returns the value of attribute target_class.
Instance Method Summary collapse
- #always_return_ref_with_sti_base? ⇒ Boolean
- #description ⇒ Object
-
#initialize(name, target_class, options) ⇒ Association
constructor
A new instance of Association.
- #method_name ⇒ Object
- #polymorphic? ⇒ Boolean
- #run_on(model, context, helper_instance = Object.new) ⇒ Object
Methods included from Concerns::Lookup
Constructor Details
#initialize(name, target_class, options) ⇒ Association
Returns a new instance of Association.
10 11 12 13 14 |
# File 'lib/brainstem/dsl/association.rb', line 10 def initialize(name, target_class, ) @name = name.to_s @target_class = target_class @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/brainstem/dsl/association.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/brainstem/dsl/association.rb', line 8 def @options end |
#target_class ⇒ Object (readonly)
Returns the value of attribute target_class.
8 9 10 |
# File 'lib/brainstem/dsl/association.rb', line 8 def target_class @target_class end |
Instance Method Details
#always_return_ref_with_sti_base? ⇒ Boolean
47 48 49 |
# File 'lib/brainstem/dsl/association.rb', line 47 def always_return_ref_with_sti_base? [:always_return_ref_with_sti_base] end |
#description ⇒ Object
16 17 18 |
# File 'lib/brainstem/dsl/association.rb', line 16 def description [:info].presence end |
#method_name ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/brainstem/dsl/association.rb', line 20 def method_name if [:dynamic] || [:lookup] nil else ([:via].presence || name).to_s end end |
#polymorphic? ⇒ Boolean
43 44 45 |
# File 'lib/brainstem/dsl/association.rb', line 43 def polymorphic? target_class == :polymorphic end |
#run_on(model, context, helper_instance = Object.new) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/brainstem/dsl/association.rb', line 28 def run_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 else model.send(method_name) end end |