Sha256: a674f1c946f0b495478170e4d5a6226ea376f9f066c2cb7f514506f37fc689cf

Contents?: true

Size: 841 Bytes

Versions: 4

Compression:

Stored size: 841 Bytes

Contents

module Yaks
  class Mapper
    class HasMany < Association
      include Util,
              attributes.add(collection_mapper: Undefined)

      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

      undef collection_mapper
      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

      def singular_name
        singularize(name.to_s)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yaks-0.13.0 lib/yaks/mapper/has_many.rb
yaks-0.12.0 lib/yaks/mapper/has_many.rb
yaks-0.11.0 lib/yaks/mapper/has_many.rb
yaks-0.10.0 lib/yaks/mapper/has_many.rb