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.



63
64
65
# File 'lib/mighty_json/type.rb', line 63

def initialize(type)
  @type = type
end

Instance Method Details

#compile(var:, path:) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/mighty_json/type.rb', line 67

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



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

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