Sha256: 58ad975588d1724663eecac10b0b54c6e37d62f89e3ebc6b12fc5f8f3624cdfb

Contents?: true

Size: 924 Bytes

Versions: 18

Compression:

Stored size: 924 Bytes

Contents

module Representable::JSON
  module Collection
    include Representable::JSON
    
    def self.included(base)
      base.class_eval do
        include Representable
        extend ClassMethods
      end
    end
    
    
    module ClassMethods
      def items(options)
        collection :_self, options
      end
    end
    
    
    def create_representation_with(doc, options, format)
      bin   = representable_bindings_for(format).first
      bin.serialize_for(self)
    end
    
    def update_properties_from(doc, options, format)
      bin   = representable_bindings_for(format).first
      value = bin.deserialize_from(doc)
      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

18 entries across 18 versions & 1 rubygems

Version Path
representable-1.2.9 lib/representable/json/collection.rb
representable-1.2.8 lib/representable/json/collection.rb
representable-1.2.7 lib/representable/json/collection.rb
representable-1.2.6 lib/representable/json/collection.rb
representable-1.2.5 lib/representable/json/collection.rb
representable-1.2.4 lib/representable/json/collection.rb
representable-1.2.3 lib/representable/json/collection.rb
representable-1.2.2 lib/representable/json/collection.rb
representable-1.2.1 lib/representable/json/collection.rb
representable-1.2.0 lib/representable/json/collection.rb
representable-1.1.7 lib/representable/json/collection.rb
representable-1.1.6 lib/representable/json/collection.rb
representable-1.1.5 lib/representable/json/collection.rb
representable-1.1.4 lib/representable/json/collection.rb
representable-1.1.3 lib/representable/json/collection.rb
representable-1.1.2 lib/representable/json/collection.rb
representable-1.1.1 lib/representable/json/collection.rb
representable-1.1.0 lib/representable/json/collection.rb