Class: ActiveRecordCompose::InnerModelCollection
- Inherits:
-
Object
- Object
- ActiveRecordCompose::InnerModelCollection
- Includes:
- Enumerable
- Defined in:
- lib/active_record_compose/inner_model_collection.rb
Instance Method Summary collapse
-
#<<(model) ⇒ InnerModelCollection
Appends model to collection.
-
#__each_by_wrapped {|rawpped| ... } ⇒ Enumerator, InnerModelCollection
Enumerates model objects, but it should be noted that application developers are not expected to use this interface.
-
#clear ⇒ InnerModelCollection
Set to empty.
-
#delete(model, context: :save) ⇒ InnerModelCollection?
Removes the specified model from the collection.
-
#each {|the| ... } ⇒ Enumerator, InnerModelCollection
Enumerates model objects.
-
#empty? ⇒ Boolean
Returns true if the element exists.
-
#push(model, context: :save) ⇒ InnerModelCollection
Appends model to collection.
Instance Method Details
#<<(model) ⇒ InnerModelCollection
Appends model to collection.
25 26 27 28 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 25 def <<(model) models << wrap(model, context: :save) self end |
#__each_by_wrapped {|rawpped| ... } ⇒ Enumerator, InnerModelCollection
Enumerates model objects, but it should be noted that application developers are not expected to use this interface.
73 74 75 76 77 78 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 73 def __each_by_wrapped return enum_for(:__each_by_wrapped) unless block_given? models.each { yield _1 } self end |
#clear ⇒ InnerModelCollection
Set to empty.
48 49 50 51 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 48 def clear models.clear self end |
#delete(model, context: :save) ⇒ InnerModelCollection?
Removes the specified model from the collection. Returns nil if the deletion fails, self if it succeeds.
60 61 62 63 64 65 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 60 def delete(model, context: :save) wrapped = wrap(model, context:) return nil unless models.delete(wrapped) self end |
#each {|the| ... } ⇒ Enumerator, InnerModelCollection
Enumerates model objects.
14 15 16 17 18 19 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 14 def each return enum_for(:each) unless block_given? models.each { yield _1.__raw_model } self end |
#empty? ⇒ Boolean
Returns true if the element exists.
43 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 43 def empty? = models.empty? |
#push(model, context: :save) ⇒ InnerModelCollection
Appends model to collection.
35 36 37 38 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 35 def push(model, context: :save) models << wrap(model, context:) self end |