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
- #polymorphic_classes ⇒ Object
- #response_key ⇒ Object
- #run_on(model, context, helper_instance = Object.new) ⇒ Object
- #type ⇒ 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
59 60 61 |
# File 'lib/brainstem/dsl/association.rb', line 59 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
32 33 34 35 36 37 38 |
# File 'lib/brainstem/dsl/association.rb', line 32 def method_name if [:dynamic] || [:lookup] nil else ([:via].presence || name).to_s end end |
#polymorphic? ⇒ Boolean
55 56 57 |
# File 'lib/brainstem/dsl/association.rb', line 55 def polymorphic? target_class == :polymorphic end |
#polymorphic_classes ⇒ Object
24 25 26 |
# File 'lib/brainstem/dsl/association.rb', line 24 def polymorphic_classes [:polymorphic_classes] end |
#response_key ⇒ Object
20 21 22 |
# File 'lib/brainstem/dsl/association.rb', line 20 def response_key [:response_key] end |
#run_on(model, context, helper_instance = Object.new) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/brainstem/dsl/association.rb', line 40 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 |
#type ⇒ Object
28 29 30 |
# File 'lib/brainstem/dsl/association.rb', line 28 def type [:type] end |