Sha256: 423107fa5fd797c4491fdb3c3d264bb012dca84002d663ddd5e23ed9acfd99f7

Contents?: true

Size: 969 Bytes

Versions: 3

Compression:

Stored size: 969 Bytes

Contents

module Representable::XML
  module Collection
    include Representable::XML

    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, options).first
      bin.write(doc, represented)
    end

    def update_properties_from(doc, options, format)
      bin   = representable_bindings_for(format, options).first
      value = bin.deserialize_from(doc.search("./*")) # FIXME: use Binding#read.
      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

3 entries across 3 versions & 1 rubygems

Version Path
representable-1.5.3 lib/representable/xml/collection.rb
representable-1.5.2 lib/representable/xml/collection.rb
representable-1.5.1 lib/representable/xml/collection.rb