Class: Sumaki::Model::Associations::Collection
- Inherits:
-
Object
- Object
- Sumaki::Model::Associations::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/sumaki/model/associations/collection.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#reflection ⇒ Object
Returns the value of attribute reflection.
Class Method Summary collapse
Instance Method Summary collapse
- #<< ⇒ Object
- #build(attrs = {}) ⇒ Object
-
#initialize(models = [], owner:) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(models = [], owner:) ⇒ Collection
Returns a new instance of Collection.
24 25 26 27 |
# File 'lib/sumaki/model/associations/collection.rb', line 24 def initialize(models = [], owner:) @models = models @owner = owner end |
Instance Attribute Details
#reflection ⇒ Object
Returns the value of attribute reflection.
12 13 14 |
# File 'lib/sumaki/model/associations/collection.rb', line 12 def reflection @reflection end |
Class Method Details
.build_subclass(reflection) ⇒ Object
18 19 20 21 22 |
# File 'lib/sumaki/model/associations/collection.rb', line 18 def self.build_subclass(reflection) subclass = Class.new(self) subclass.reflection = reflection subclass end |
Instance Method Details
#<< ⇒ Object
39 40 41 42 43 |
# File 'lib/sumaki/model/associations/collection.rb', line 39 def <<(...) r = @models.<<(...) apply r end |
#build(attrs = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/sumaki/model/associations/collection.rb', line 29 def build(attrs = {}) object = @owner.object_accessor.build_repeated_element(reflection.name) model = reflection.model_class.new(object, parent: @owner) model.assign(attrs) self << model model end |