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.



40
41
42
# File 'lib/strong_json/type.rb', line 40

def initialize(type)
  @type = type
end

Instance Method Details

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



44
45
46
47
48
49
50
# File 'lib/strong_json/type.rb', line 44

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

#to_sObject



52
53
54
# File 'lib/strong_json/type.rb', line 52

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