Sha256: 1743e73d1b15c54679db0985149312ade310ec7a550ebec1f4d63240cbe9ee48

Contents?: true

Size: 428 Bytes

Versions: 50

Compression:

Stored size: 428 Bytes

Contents

# frozen_string_literal: true

module Hako
  module Schema
    class WithDefault
      def initialize(schema, default)
        @schema = schema
        @default = default
      end

      def valid?(object)
        object.nil? || @schema.valid?(object)
      end

      def same?(x, y)
        @schema.same?(wrap(x), wrap(y))
      end

      private

      def wrap(x)
        x.nil? ? @default : x
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
hako-2.4.0 lib/hako/schema/with_default.rb
hako-2.3.1 lib/hako/schema/with_default.rb
hako-2.3.0 lib/hako/schema/with_default.rb
hako-2.2.0 lib/hako/schema/with_default.rb
hako-2.1.0 lib/hako/schema/with_default.rb
hako-2.0.4 lib/hako/schema/with_default.rb
hako-2.0.3 lib/hako/schema/with_default.rb
hako-2.0.2 lib/hako/schema/with_default.rb
hako-2.0.1 lib/hako/schema/with_default.rb
hako-2.0.0 lib/hako/schema/with_default.rb
hako-1.9.0 lib/hako/schema/with_default.rb
hako-1.8.4 lib/hako/schema/with_default.rb
hako-1.8.3 lib/hako/schema/with_default.rb
hako-1.8.2 lib/hako/schema/with_default.rb
hako-1.8.1 lib/hako/schema/with_default.rb
hako-1.8.0 lib/hako/schema/with_default.rb
hako-1.7.0 lib/hako/schema/with_default.rb
hako-1.6.2 lib/hako/schema/with_default.rb
hako-1.6.1 lib/hako/schema/with_default.rb
hako-1.6.0 lib/hako/schema/with_default.rb