Class: Consumerable::Associations::HasManyProxy
- Inherits:
- BasicObject
- Defined in:
- lib/consumerable/associations/has_many_proxy.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#target_klass ⇒ Object
readonly
Returns the value of attribute target_klass.
Instance Method Summary collapse
- #build(attributes) ⇒ Object
- #create(attributes = {}) ⇒ Object
-
#initialize(parent, target_klass, target, source) ⇒ HasManyProxy
constructor
A new instance of HasManyProxy.
- #method_missing(name, *args, &block) ⇒ Object
- #tap {|_self| ... } ⇒ Object
Constructor Details
#initialize(parent, target_klass, target, source) ⇒ HasManyProxy
Returns a new instance of HasManyProxy.
7 8 9 10 11 12 |
# File 'lib/consumerable/associations/has_many_proxy.rb', line 7 def initialize(parent, target_klass, target, source) @parent = parent @target_klass = target_klass @target = target @source = source end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
14 15 16 |
# File 'lib/consumerable/associations/has_many_proxy.rb', line 14 def method_missing(name, *args, &block) target.send(name, *args, &block) end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/consumerable/associations/has_many_proxy.rb', line 5 def parent @parent end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/consumerable/associations/has_many_proxy.rb', line 5 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
5 6 7 |
# File 'lib/consumerable/associations/has_many_proxy.rb', line 5 def target @target end |
#target_klass ⇒ Object (readonly)
Returns the value of attribute target_klass.
5 6 7 |
# File 'lib/consumerable/associations/has_many_proxy.rb', line 5 def target_klass @target_klass end |
Instance Method Details
#build(attributes) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/consumerable/associations/has_many_proxy.rb', line 22 def build(attributes) target_klass.new(attributes).tap do |item| item.send("#{source}=", parent) target << item end end |
#create(attributes = {}) ⇒ Object
18 19 20 |
# File 'lib/consumerable/associations/has_many_proxy.rb', line 18 def create(attributes = {}) build(attributes).save end |
#tap {|_self| ... } ⇒ Object
29 30 31 32 |
# File 'lib/consumerable/associations/has_many_proxy.rb', line 29 def tap yield self self end |