Sha256: c9fa9d158f601f88a1cbb43ba917536c34c560893e4de7bc34cbdf4af7adb5d5

Contents?: true

Size: 719 Bytes

Versions: 4

Compression:

Stored size: 719 Bytes

Contents

module Compel
  module Builder

    class Hash < Schema

      def initialize
        super(Coercion::Hash)

        options[:keys] = { value: {} }
      end

      def keys(object, options = {})
        build_option :keys, coerce_keys_schemas(object), options
      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

4 entries across 4 versions & 1 rubygems

Version Path
compel-0.5.1 lib/compel/builder/hash.rb
compel-0.5.0 lib/compel/builder/hash.rb
compel-0.4.3 lib/compel/builder/hash.rb
compel-0.4.2 lib/compel/builder/hash.rb