Class: MightyJSON::Type::Array
- Inherits:
-
Object
- Object
- MightyJSON::Type::Array
- Defined in:
- lib/mighty_json/type.rb
Instance Method Summary collapse
- #compile(var:, path:) ⇒ Object
-
#initialize(type) ⇒ Array
constructor
A new instance of Array.
- #to_s ⇒ Object
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 <<~END begin raise Error.new(path: #{path.inspect}, type: #{self.to_s.inspect}, value: #{v}) unless #{v}.is_a?(::Array) #{v}.map.with_index do |#{child}, #{idx}| #{@type.compile(var: var, path: path + [Eval.new(idx)])} end end END end |
#to_s ⇒ Object
134 135 136 |
# File 'lib/mighty_json/type.rb', line 134 def to_s "array(#{@type})" end |