Sha256: a8697bc34478c6d9441d80ceb033aecd885be45c0fadba71f8782e3a089bfdbe

Contents?: true

Size: 817 Bytes

Versions: 7

Compression:

Stored size: 817 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.write(doc, represented)
    end

    def update_properties_from(doc, options, format)
      bin   = representable_mapper(format, options).bindings.first
      value = bin.deserialize_from(doc)
      represented.replace(value)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
representable-2.0.4 lib/representable/hash/collection.rb
representable-2.0.3 lib/representable/hash/collection.rb
representable-2.0.2 lib/representable/hash/collection.rb
representable-2.0.1 lib/representable/hash/collection.rb
representable-2.0.0 lib/representable/hash/collection.rb
representable-2.0.0.rc2 lib/representable/hash/collection.rb
representable-2.0.0.rc1 lib/representable/hash/collection.rb