Sha256: 61c927d4d356d2c2c278bbc3d60bc95e0f8fc8a7875d206b6fd2e9c79d9437e3

Contents?: true

Size: 695 Bytes

Versions: 3

Compression:

Stored size: 695 Bytes

Contents

module Compel
  module Builder

    class Hash < Schema

      def initialize
        super(Coercion::Hash)

        options[:keys] = {}
      end

      def keys(object)
        options[:keys] = coerce_keys_schemas(object)
        self
      end

      private

      def coerce_keys_schemas(object)
        begin
          fail if object.nil?

          Coercion.coerce!(object, Coercion::Hash)
        rescue
          raise TypeError, 'Builder::Hash keys must be an Hash'
        end

        unless object.values.all?{|value| value.is_a?(Builder::Schema) }
          raise TypeError, 'All Builder::Hash keys must be a valid Schema'
        end

        object
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
compel-0.4.0 lib/compel/builder/hash.rb
compel-0.3.7 lib/compel/builder/hash.rb
compel-0.3.6 lib/compel/builder/hash.rb