Sha256: a119eb5fc0b33ee58dad1ba65d087729945fb63d80c444f84c7215e78359f2c8

Contents?: true

Size: 974 Bytes

Versions: 11

Compression:

Stored size: 974 Bytes

Contents

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

    def self.included(base)
      base.class_eval do
        include Representable
        extend ClassMethods
      end
    end


    module ClassMethods
      def items(options)
        collection :_self, options.merge(:getter => lambda { |*| self })
      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

    # FIXME: refactor Definition so we can simply add options in #items to existing definition.
    def representable_attrs
      attrs = super
      attrs << Definition.new(:_self, :collection => true) if attrs.size == 0
      attrs
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
representable-1.8.2 lib/representable/hash/collection.rb
representable-1.8.1 lib/representable/hash/collection.rb
representable-1.8.0 lib/representable/hash/collection.rb
representable-1.7.7 lib/representable/hash/collection.rb
representable-1.7.6 lib/representable/hash/collection.rb
representable-1.7.5 lib/representable/hash/collection.rb
representable-1.7.4 lib/representable/hash/collection.rb
representable-1.7.3 lib/representable/hash/collection.rb
representable-1.7.2 lib/representable/hash/collection.rb
representable-1.7.1 lib/representable/hash/collection.rb
representable-1.7.0 lib/representable/hash/collection.rb