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) ⇒ self
Appends model to collection.
-
#__each_by_wrapped {|rawpped| ... } ⇒ Enumerator, self
Enumerates model objects, but it should be noted that application developers are not expected to use this interface.
-
#clear ⇒ self
Set to empty.
-
#delete(model) ⇒ self?
Removes the specified model from the collection.
-
#each {|the| ... } ⇒ Enumerator, self
Enumerates model objects.
-
#empty? ⇒ Boolean
Returns true if the element exists.
-
#initialize(owner) ⇒ InnerModelCollection
constructor
A new instance of InnerModelCollection.
-
#push(model, destroy: false) ⇒ self
Appends model to collection.
Constructor Details
#initialize(owner) ⇒ InnerModelCollection
Returns a new instance of InnerModelCollection.
9 10 11 12 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 9 def initialize(owner) @owner = owner @models = [] end |
Instance Method Details
#<<(model) ⇒ self
Appends model to collection.
30 31 32 33 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 30 def <<(model) models << wrap(model, destroy: false) self end |
#__each_by_wrapped {|rawpped| ... } ⇒ Enumerator, self
Enumerates model objects, but it should be noted that application developers are not expected to use this interface.
80 81 82 83 84 85 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 80 def __each_by_wrapped return enum_for(:__each_by_wrapped) unless block_given? models.each { yield _1 if _1.__raw_model } # steep:ignore self end |
#clear ⇒ self
Set to empty.
55 56 57 58 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 55 def clear models.clear self end |
#delete(model) ⇒ self?
Removes the specified model from the collection. Returns nil if the deletion fails, self if it succeeds.
66 67 68 69 70 71 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 66 def delete(model) wrapped = wrap(model) return nil unless models.delete(wrapped) self end |
#each {|the| ... } ⇒ Enumerator, self
Enumerates model objects.
19 20 21 22 23 24 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 19 def each return enum_for(:each) unless block_given? models.each { yield _1.__raw_model } # steep:ignore self end |
#empty? ⇒ Boolean
Returns true if the element exists.
50 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 50 def empty? = models.empty? |
#push(model, destroy: false) ⇒ self
Appends model to collection.
42 43 44 45 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 42 def push(model, destroy: false) models << wrap(model, destroy:) self end |