module Representable::Hash::Collection

Public Class Methods

included(base) click to toggle source
# File lib/representable/hash/collection.rb, line 5
def self.included(base)
  base.class_eval do
    include Representable::Hash
    extend ClassMethods
    property(:_self, {:collection => true})
  end
end

Public Instance Methods

create_representation_with(doc, options, format) click to toggle source

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

# File lib/representable/hash/collection.rb, line 22
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
update_properties_from(doc, options, format) click to toggle source
# File lib/representable/hash/collection.rb, line 32
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