Sha256: fcc60c8c2802c4b8f6345df83e8732f7ddff6116750b96811970fdd990f54d91

Contents?: true

Size: 1.28 KB

Versions: 9

Compression:

Stored size: 1.28 KB

Contents

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

    def self.included(base)
      base.class_eval do
        include Representable::Hash
        extend ClassMethods
        property(:_self, {:collection => true})
      end
    end


    module ClassMethods
      def items(options={}, &block)
        collection(:_self, options.merge(:getter => lambda { |*| self }), &block)
      end
    end

    # TODO: revise lonely collection and build separate pipeline where we just use Serialize, etc.

    def create_representation_with(doc, options, format)
      options = normalize_options(options)
      options[:_self] = options

      bin   = representable_bindings_for(format, options).first

      Collect[*bin.default_render_fragment_functions].
        (represented, {doc: doc, fragment: represented, options: options, binding: bin, represented: represented})
    end

    def update_properties_from(doc, options, format)
      options = normalize_options(options)
      options[:_self] = options

      bin   = representable_bindings_for(format, options).first

      value = Collect[*bin.default_parse_fragment_functions].
        (doc, fragment: doc, document: doc, options: options, binding: bin, represented: represented)

      represented.replace(value)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
representable-3.0.4 lib/representable/hash/collection.rb
representable-3.0.3 lib/representable/hash/collection.rb
representable-3.0.2 lib/representable/hash/collection.rb
representable-3.0.1 lib/representable/hash/collection.rb
representable-3.0.0 lib/representable/hash/collection.rb
representable-2.4.1 lib/representable/hash/collection.rb
representable-2.4.0 lib/representable/hash/collection.rb
representable-2.4.0.rc5 lib/representable/hash/collection.rb
representable-2.4.0.rc4 lib/representable/hash/collection.rb