Module: Gorillib::Collection::CommonAttrs

Extended by:
Gorillib::Concern
Included in:
ItemsBelongTo
Defined in:
lib/gorillib/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

Methods included from Gorillib::Concern

append_features, extended, included

Instance Method Details

#initialize(options = {}) ⇒ Object



81
82
83
84
# File 'lib/gorillib/collection/model_collection.rb', line 81

def initialize(options={})
  super
  @common_attrs = self.common_attrs.merge(options[:common_attrs]) if options.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/collection/model_collection.rb', line 90

def receive_item(label, *args, &block)
  attrs = args.extract_options!.merge(common_attrs)
  super(label, *args, attrs, &block)
end

#update_or_add(label, *args, &block) ⇒ Object



95
96
97
98
# File 'lib/gorillib/collection/model_collection.rb', line 95

def update_or_add(label, *args, &block)
  attrs = args.extract_options!.merge(common_attrs)
  super(label, *args, attrs, &block)
end