Sha256: 2f8d10379ab6b89ec6b12708653c4b57ec176554c7f4cc64cf527e52bb7ed38b

Contents?: true

Size: 973 Bytes

Versions: 16

Compression:

Stored size: 973 Bytes

Contents

module Representable
  module HashMethods
    # FIXME: refactor Definition so we can simply add options in #items to existing definition.
    def representable_attrs
      attrs = super
      attrs << Definition.new(*definition_opts) if attrs.size == 0
      attrs
    end

    def create_representation_with(doc, options, format)
      bin   = representable_mapper(format, options).bindings.first
      hash  = filter_keys_for(represented, options)
      bin.write(doc, hash)
    end

    def update_properties_from(doc, options, format)
      bin   = representable_mapper(format, options).bindings.first
      hash  = filter_keys_for(doc, options)
      value = bin.deserialize_from(hash)
      represented.replace(value)
    end

  private
    def filter_keys_for(hash, options)
      return hash unless props = options[:exclude] || options[:include]
      hash.reject { |k,v| options[:exclude] ? props.include?(k.to_sym) : !props.include?(k.to_sym) }
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
representable-1.8.5 lib/representable/hash_methods.rb
representable-1.8.4 lib/representable/hash_methods.rb
representable-1.8.3 lib/representable/hash_methods.rb
representable-1.8.2 lib/representable/hash_methods.rb
representable-1.8.1 lib/representable/hash_methods.rb
representable-1.8.0 lib/representable/hash_methods.rb
representable-1.7.7 lib/representable/hash_methods.rb
representable-1.7.6 lib/representable/hash_methods.rb
representable-1.7.5 lib/representable/hash_methods.rb
representable-1.7.4 lib/representable/hash_methods.rb
representable-1.7.3 lib/representable/hash_methods.rb
representable-1.7.2 lib/representable/hash_methods.rb
representable-1.7.1 lib/representable/hash_methods.rb
representable-1.7.0 lib/representable/hash_methods.rb
representable-1.6.1 lib/representable/hash_methods.rb
representable-1.6.0 lib/representable/hash_methods.rb