Class: Copper::Functions::Fetch

Inherits:
CopperNode
  • Object
show all
Includes:
ExpressionUtils
Defined in:
lib/copper/functions/fetch.rb

Instance Method Summary collapse

Methods included from ExpressionUtils

#handle_attributes

Instance Method Details

#value(vars = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/copper/functions/fetch.rb', line 9

def value(vars = {})
	key = elements[0].value(vars)
	context = vars[:context]

	begin
		path = JsonPath.new(key)
		result = path.on(context)
	rescue ArgumentError => exc
		raise ParseError, "JSONPath error #{key}: #{exc.message}"
	rescue NoMethodError => exc
		raise ParseError, "JSONPath error #{key}. Invalid JSONPath"
	end

	return handle_attributes(result, vars)
end