Sha256: 69c60303da7641728ffeb3922d3f8116937e67acbbd8fb1d00525bf980fe5001

Contents?: true

Size: 636 Bytes

Versions: 7

Compression:

Stored size: 636 Bytes

Contents

require 'representable/binding'

module Representable
  module Hash
    class Binding < Representable::Binding
      def self.build_for(definition)
        return Collection.new(definition) if definition.array?
        new(definition)
      end

      def read(hash, as)
        hash.has_key?(as) ? hash[as] : FragmentNotFound
      end

      def write(hash, fragment, as)
        hash[as] = fragment
      end

      def serialize_method
        :to_hash
      end

      def deserialize_method
        :from_hash
      end

      class Collection < self
        include Representable::Binding::Collection
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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