Sha256: 07e59d6432d8e9d060ecb71d1b1942cd914327823abceee31693fbd58d531471

Contents?: true

Size: 878 Bytes

Versions: 4

Compression:

Stored size: 878 Bytes

Contents

# -*- coding: utf-8 -*-

module Yaks
  class CollectionMapper
    include Util, Mapper::MapLinks, SharedOptions
    extend Mapper::ClassMethods

    attr_reader :collection, :resource_mapper, :options
    private :collection, :resource_mapper, :options

    def_delegators 'self.class', :config
    def_delegators :config, :links

    def initialize(collection, resource_mapper, options = {})
      @collection      = collection
      @resource_mapper = resource_mapper
      @options         = YAKS_DEFAULT_OPTIONS.merge(options)
    end

    def to_resource
      CollectionResource.new(map_links, collection.map {|obj| resource_mapper.new(obj, options).to_resource})
    end

    def load_attribute(name)
      respond_to?(name) ? send(name) : collection.map(&name.to_sym)
    end

    def profile_type
      resource_mapper.new(nil, options).profile_type
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yaks-0.3.1 lib/yaks/collection_mapper.rb
yaks-0.3.0 lib/yaks/collection_mapper.rb
yaks-0.2.0 lib/yaks/collection_mapper.rb
yaks-0.1.0 lib/yaks/collection_mapper.rb