Class: Hako::Schema::WithDefault

Inherits:
Object
  • Object
show all
Defined in:
lib/hako/schema/with_default.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema, default) ⇒ WithDefault

Returns a new instance of WithDefault.



6
7
8
9
# File 'lib/hako/schema/with_default.rb', line 6

def initialize(schema, default)
  @schema = schema
  @default = default
end

Instance Method Details

#same?(x, y) ⇒ Boolean

Returns:



15
16
17
# File 'lib/hako/schema/with_default.rb', line 15

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

#valid?(object) ⇒ Boolean

Returns:



11
12
13
# File 'lib/hako/schema/with_default.rb', line 11

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

#wrap(x) ⇒ Object (private)



21
22
23
# File 'lib/hako/schema/with_default.rb', line 21

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