Class: ActiveRecordCompose::InnerModelCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_record_compose/inner_model_collection.rb

Instance Method Summary collapse

Constructor Details

#initializeInnerModelCollection

Returns a new instance of InnerModelCollection.



9
10
11
# File 'lib/active_record_compose/inner_model_collection.rb', line 9

def initialize
  @inner_models = []
end

Instance Method Details

#<<(inner_model) ⇒ Object



20
21
22
23
# File 'lib/active_record_compose/inner_model_collection.rb', line 20

def <<(inner_model)
  inner_models << wrap(inner_model, context: :save)
  self
end

#eachObject



13
14
15
16
17
18
# File 'lib/active_record_compose/inner_model_collection.rb', line 13

def each
  return enum_for(:each) unless block_given?

  inner_models.each { yield _1 }
  self
end

#push(inner_model, context: :save) ⇒ Object



25
26
27
28
# File 'lib/active_record_compose/inner_model_collection.rb', line 25

def push(inner_model, context: :save)
  inner_models << wrap(inner_model, context:)
  self
end