Class: Yaks::Mapper::HasMany

Inherits:
Association show all
Includes:
Util
Defined in:
lib/yaks/mapper/has_many.rb

Instance Method Summary collapse

Methods included from Util

#Resolve, #camelize, #extract_options, #reject_keys, #slice_hash, #symbolize_keys, #underscore

Methods inherited from Association

#add_to_resource, create, #map_rel, #render_as_link?, #resolve_association_mapper

Instance Method Details

#collection_mapper(collection = nil, policy = nil) ⇒ Object



16
17
18
19
# File 'lib/yaks/mapper/has_many.rb', line 16

def collection_mapper(collection = nil, policy = nil)
  return @collection_mapper unless @collection_mapper.equal? Undefined
  policy.derive_mapper_from_object(collection) if policy && collection
end

#map_resource(collection, context) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/yaks/mapper/has_many.rb', line 7

def map_resource(collection, context)
  return NullResource.new(collection: true) if collection.nil?
  policy      = context.fetch(:policy)
  item_mapper = resolve_association_mapper(policy)
  context     = context.merge(item_mapper: item_mapper)
  collection_mapper(collection, policy).new(context).call(collection)
end

#singular_nameObject



21
22
23
# File 'lib/yaks/mapper/has_many.rb', line 21

def singular_name
  singularize(name.to_s)
end