Class: StrongJSON::Type::Optional

Inherits:
Object
  • Object
show all
Defined in:
lib/strong_json/type.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Optional

Returns a new instance of Optional.



43
44
45
# File 'lib/strong_json/type.rb', line 43

def initialize(type)
  @type = type
end

Instance Method Details

#coerce(value, path: []) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/strong_json/type.rb', line 47

def coerce(value, path: [])
  unless value == nil || NONE.equal?(value)
    @type.coerce(value, path: path)
  else
    nil
  end
end

#to_sObject



55
56
57
# File 'lib/strong_json/type.rb', line 55

def to_s
  "optinal(#{@type})"
end