Sha256: 02daaddcd2b67e9848411e302f8bce0b913f15d6b56af756c71bb7ab450e9d1a

Contents?: true

Size: 889 Bytes

Versions: 5

Compression:

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

5 entries across 5 versions & 1 rubygems

Version Path
representable-2.1.8 lib/representable/hash/collection.rb
representable-2.1.7 lib/representable/hash/collection.rb
representable-2.1.6 lib/representable/hash/collection.rb
representable-2.1.5 lib/representable/hash/collection.rb
representable-2.1.4 lib/representable/hash/collection.rb