Module: Gorillib::Collection::CommonAttrs
- Extended by:
- ActiveSupport::Concern
- Included in:
- ItemsBelongTo
- Defined in:
- lib/gorillib/model/collection/model_collection.rb
Overview
class ClusterCollection < ModelCollection
self.item_type = Cluster
end
class Organization
field :clusters, ClusterCollection, default: ->{ ClusterCollection.new(common_attrs: { organization: self }) }
end
Instance Method Summary collapse
- #initialize(options = {}) ⇒ Object
-
#receive_item(label, *args, &block) ⇒ Object
-
a factory-native object: item is updated with common_attrs, then added * raw materials for the object: item is constructed (from the merged attrs and common_attrs), then added.
-
- #update_or_add(label, *args, &block) ⇒ Object
Instance Method Details
#initialize(options = {}) ⇒ Object
81 82 83 84 |
# File 'lib/gorillib/model/collection/model_collection.rb', line 81 def initialize(={}) super @common_attrs = self.common_attrs.merge([:common_attrs]) if .include?(:common_attrs) end |
#receive_item(label, *args, &block) ⇒ Object
-
a factory-native object: item is updated with common_attrs, then added
-
raw materials for the object: item is constructed (from the merged attrs and common_attrs), then added
90 91 92 93 |
# File 'lib/gorillib/model/collection/model_collection.rb', line 90 def receive_item(label, *args, &block) attrs = args..merge(common_attrs) super(label, *args, attrs, &block) end |
#update_or_add(label, *args, &block) ⇒ Object
95 96 97 98 |
# File 'lib/gorillib/model/collection/model_collection.rb', line 95 def update_or_add(label, *args, &block) attrs = args..merge(common_attrs) super(label, *args, attrs, &block) end |