Sha256: 252520a7eab0ecae433de68a2ab919dbae6bf086b1b42ab2eb57e08aec53906e

Contents?: true

Size: 886 Bytes

Versions: 3

Compression:

Stored size: 886 Bytes

Contents

module Representable::Hash
  module Collection
    include Representable::Hash

    def self.included(base)
      base.class_eval do
        include Representable::Hash
        extend ClassMethods
        representable_attrs.add(:_self, {:collection => true})
      end
    end


    module ClassMethods
      def items(options, &block)
        collection(:_self, options.merge(:getter => lambda { |*| self }), &block)
      end
    end


    def create_representation_with(doc, options, format)
      bin   = representable_mapper(format, options).bindings.first
      bin.render_fragment(represented, doc)
    end

    def update_properties_from(doc, options, format)
      bin   = representable_mapper(format, options).bindings.first
      #value = bin.deserialize_from(doc)
      value = Deserializer::Collection.new(bin).call(doc)
      represented.replace(value)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
representable-2.1.3 lib/representable/hash/collection.rb
representable-2.1.1 lib/representable/hash/collection.rb
representable-2.1.0 lib/representable/hash/collection.rb