module Gorillib::Collection::CommonAttrs

class ClusterCollection < ModelCollection

self.item_type = Cluster

end class Organization

field :clusters, ClusterCollection, default: ->{ ClusterCollection.new(common_attrs: { organization: self }) }

end

Public Class Methods

new(options={}) click to toggle source
Calls superclass method
# 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

Public Instance Methods

receive_item(label, *args, &block) click to toggle source
  • 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

Calls superclass method
# 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) click to toggle source
Calls superclass method
# 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