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.
102 103 104 |
# File 'lib/mighty_json/type.rb', line 102 def initialize(type) @type = type end |
Instance Method Details
#compile(var:, path:) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/mighty_json/type.rb', line 106 def compile(var:, path:) v = var.cur 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}, i| #{@type.compile(var: var, path: path + [:array_index])} # TODO: optimize path end end END end |
#to_s ⇒ Object
119 120 121 |
# File 'lib/mighty_json/type.rb', line 119 def to_s "array(#{@type})" end |