Sha256: 85193d0544332a35e2b20e87e5bef8e9ee87b3c7c9a495d084bfd2ac85ce438f

Contents?: true

Size: 811 Bytes

Versions: 19

Compression:

Stored size: 811 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

      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

19 entries across 19 versions & 1 rubygems

Version Path
yaks-0.9.0 lib/yaks/mapper/has_many.rb
yaks-0.8.3 lib/yaks/mapper/has_many.rb
yaks-0.8.2 lib/yaks/mapper/has_many.rb
yaks-0.8.1 lib/yaks/mapper/has_many.rb
yaks-0.8.0 lib/yaks/mapper/has_many.rb
yaks-0.8.0.beta2 lib/yaks/mapper/has_many.rb
yaks-0.8.0.beta1 lib/yaks/mapper/has_many.rb
yaks-0.8.0.alpha lib/yaks/mapper/has_many.rb
yaks-0.7.7 lib/yaks/mapper/has_many.rb
yaks-0.7.6 lib/yaks/mapper/has_many.rb
yaks-0.7.5 lib/yaks/mapper/has_many.rb
yaks-0.7.4 lib/yaks/mapper/has_many.rb
yaks-0.7.3 lib/yaks/mapper/has_many.rb
yaks-0.7.2 lib/yaks/mapper/has_many.rb
yaks-0.7.1 lib/yaks/mapper/has_many.rb
yaks-0.7.0 lib/yaks/mapper/has_many.rb
yaks-0.6.2 lib/yaks/mapper/has_many.rb
yaks-0.6.1 lib/yaks/mapper/has_many.rb
yaks-0.6.0 lib/yaks/mapper/has_many.rb