Sha256: 554cad7007ee1c08463e4cbf5f7381819e645272f31fc780c212c5bcd2e33fd5

Contents?: true

Size: 427 Bytes

Versions: 11

Compression:

Stored size: 427 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

11 entries across 11 versions & 1 rubygems

Version Path
hako-1.1.0 lib/hako/schema/with_default.rb
hako-1.0.1 lib/hako/schema/with_default.rb
hako-1.0.0 lib/hako/schema/with_default.rb
hako-0.27.0 lib/hako/schema/with_default.rb
hako-0.26.0 lib/hako/schema/with_default.rb
hako-0.25.2 lib/hako/schema/with_default.rb
hako-0.25.1 lib/hako/schema/with_default.rb
hako-0.25.0 lib/hako/schema/with_default.rb
hako-0.24.0 lib/hako/schema/with_default.rb
hako-0.23.0 lib/hako/schema/with_default.rb
hako-0.22.0 lib/hako/schema/with_default.rb