Class: MightyJSON::Type::Array

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

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Array

Returns a new instance of Array.



116
117
118
# File 'lib/mighty_json/type.rb', line 116

def initialize(type)
  @type = type
end

Instance Method Details

#compile(var:, path:) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/mighty_json/type.rb', line 120

def compile(var:, path:)
  v = var.cur
  idx = var.next
  child = var.next
  "    begin\n      raise Error.new(path: \#{path.inspect}, type: \#{self.to_s.inspect}, value: \#{v}) unless \#{v}.is_a?(::Array)\n      \#{v}.map.with_index do |\#{child}, \#{idx}|\n        \#{@type.compile(var: var, path: path + [Eval.new(idx)])}\n      end\n    end\n  END\nend\n"

#to_sObject



134
135
136
# File 'lib/mighty_json/type.rb', line 134

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