Method: MightyJSON::Type::Enum#compile

Defined in:
lib/mighty_json/type.rb

#compile(var:, path:) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/mighty_json/type.rb', line 200

def compile(var:, path:)
  v = var.cur
  <<~END
    #{@types.map do |type|
      <<~END2.chomp
        begin
          #{type.compile(var: var, path: path)}
        rescue Error, UnexpectedFieldError, IllegalTypeError
        end
      END2
    end.join(' || ')} || (raise Error.new(path: #{path.inspect}, type: #{self.to_s.inspect}, value: #{v}))
  END
end