Class: SmoothOperator::Associations::HasManyRelation
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SmoothOperator::Associations::HasManyRelation
- Defined in:
- lib/smooth_operator/associations/has_many_relation.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #attributes ⇒ Object
- #build(attributes = {}) ⇒ Object
-
#initialize(object, association) ⇒ HasManyRelation
constructor
A new instance of HasManyRelation.
- #new(attributes = {}) ⇒ Object
- #reload ⇒ Object
Constructor Details
#initialize(object, association) ⇒ HasManyRelation
Returns a new instance of HasManyRelation.
7 8 9 |
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 7 def initialize(object, association) @object, @association = object, association end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
5 6 7 |
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 5 def association @association end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 5 def object @object end |
Instance Method Details
#attributes ⇒ Object
35 36 37 |
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 35 def attributes get_array.map(&:attributes) end |
#build(attributes = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 19 def build(attributes = {}) new_entries = if attributes.is_a?(Array) attributes.map { |attrs| new(attrs) } else [new(attributes)] end new_array = get_array new_array.push *new_entries object.send("#{association}=", new_array) attributes.is_a?(Array) ? new_entries : new_entries.first end |
#new(attributes = {}) ⇒ Object
15 16 17 |
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 15 def new(attributes = {}) object.class.reflect_on_association(association).klass.new(attributes) end |
#reload ⇒ Object
11 12 13 |
# File 'lib/smooth_operator/associations/has_many_relation.rb', line 11 def reload "TODO" end |