Sha256: d505c6f5c8ca150517419b2c0e81f8afb3ce0837641e903c37249568b1612c90

Contents?: true

Size: 741 Bytes

Versions: 7

Compression:

Stored size: 741 Bytes

Contents

module Representable
  module HashMethods
    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

7 entries across 7 versions & 1 rubygems

Version Path
representable-2.0.4 lib/representable/hash_methods.rb
representable-2.0.3 lib/representable/hash_methods.rb
representable-2.0.2 lib/representable/hash_methods.rb
representable-2.0.1 lib/representable/hash_methods.rb
representable-2.0.0 lib/representable/hash_methods.rb
representable-2.0.0.rc2 lib/representable/hash_methods.rb
representable-2.0.0.rc1 lib/representable/hash_methods.rb