Class: ActiveRecordCompose::InnerModelCollection
- Inherits:
-
Object
- Object
- ActiveRecordCompose::InnerModelCollection
- Includes:
- Enumerable
- Defined in:
- lib/active_record_compose/inner_model_collection.rb
Defined Under Namespace
Modules: PackagePrivate
Instance Method Summary collapse
-
#<<(model) ⇒ self
Appends model to collection.
-
#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, if: nil) ⇒ self
Appends model to collection.
Constructor Details
#initialize(owner) ⇒ InnerModelCollection
Returns a new instance of InnerModelCollection.
11 12 13 14 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 11 def initialize(owner) @owner = owner @models = [] end |
Instance Method Details
#<<(model) ⇒ self
Appends model to collection.
32 33 34 35 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 32 def <<(model) models << wrap(model, destroy: false) self end |
#clear ⇒ self
Set to empty.
59 60 61 62 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 59 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.
70 71 72 73 74 75 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 70 def delete(model) wrapped = wrap(model) return nil unless models.delete(wrapped) self end |
#each {|the| ... } ⇒ Enumerator, self
Enumerates model objects.
21 22 23 24 25 26 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 21 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.
54 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 54 def empty? = models.empty? |
#push(model, destroy: false, if: nil) ⇒ self
Appends model to collection.
46 47 48 49 |
# File 'lib/active_record_compose/inner_model_collection.rb', line 46 def push(model, destroy: false, if: nil) models << wrap(model, destroy:, if:) self end |