Sha256: 72228df10fe71eb35d9dba1de75adb2c6e5a55a22110773539f3fc6deb2767c3

Contents?: true

Size: 933 Bytes

Versions: 5

Compression:

Stored size: 933 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(represented, options).first
      bin.render_fragment(represented, doc)
    end

    def update_properties_from(doc, options, format)
      bin   = representable_mapper(format, options).bindings(represented, options).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.3.0 lib/representable/hash/collection.rb
representable-2.2.3 lib/representable/hash/collection.rb
representable-2.2.2 lib/representable/hash/collection.rb
representable-2.2.1 lib/representable/hash/collection.rb
representable-2.2.0 lib/representable/hash/collection.rb