Class: MightyJSON::Type::Optional

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

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Optional

Returns a new instance of Optional.



77
78
79
# File 'lib/mighty_json/type.rb', line 77

def initialize(type)
  @type = type
end

Instance Method Details

#compile(var:, path:) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/mighty_json/type.rb', line 81

def compile(var:, path:)
  v = var.cur
  "    if \#{v}.nil? || none.equal?(\#{v})\n      nil\n    else\n      \#{@type.compile(var: var, path: path)}\n    end\n  END\nend\n"

#to_sObject



92
93
94
# File 'lib/mighty_json/type.rb', line 92

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