Module: LinkedRails::Model::Collections

Extended by:
ActiveSupport::Concern
Included in:
LinkedRails::Model
Defined in:
lib/linked_rails/model/collections.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#collection_for(name, instance_opts = {}) ⇒ Collection

Initialises a Collection for one of the collections defined by has_collection

Parameters:

  • as defined with has_collection

  • Additional options to be passed to the collection.

Returns:

See Also:

  • Ldable#has_collection


21
22
23
24
25
26
27
28
29
30
# File 'lib/linked_rails/model/collections.rb', line 21

def collection_for(name, instance_opts = {})
  collection_opts = collections.detect { |c| c[:name] == name }.try(:[], :options).dup
  return if collection_opts.blank?

  collection_opts[:name] = name
  collection_opts[:parent] = self
  collection_opts[:part_of] = collection_opts.key?(:part_of) ? send(collection_opts[:part_of]) : self
  collection_class = collection_opts.delete(:collection_class) || LinkedRails.collection_class
  collection_class.collection_or_view(collection_opts, instance_opts)
end

#parent_collections(user_context) ⇒ Object



32
33
34
35
36
# File 'lib/linked_rails/model/collections.rb', line 32

def parent_collections(user_context)
  return [] if try(:parent).try(:collections).blank?

  parent_collections_for(parent, user_context)
end