Class: WebFunction::Promise::Path
- Inherits:
-
Object
- Object
- WebFunction::Promise::Path
- Defined in:
- lib/web_function/promise.rb
Overview
A path is a JSONPath expression that can be used to resolve a value from a response.
Instance Method Summary collapse
-
#[](key) ⇒ Path
Returns a new path with the given key.
-
#initialize(path) ⇒ Path
constructor
A new instance of Path.
-
#mutate(path) ⇒ Path
Mutates the path with the given path.
-
#to_json(*args) ⇒ String
Returns the JSON representation of the path.
-
#to_s ⇒ String
Returns the string representation of the path.
Constructor Details
#initialize(path) ⇒ Path
Returns a new instance of Path.
26 27 28 |
# File 'lib/web_function/promise.rb', line 26 def initialize(path) @path = path end |
Instance Method Details
#[](key) ⇒ Path
Returns a new path with the given key.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/web_function/promise.rb', line 54 def [](key) case key when String, Symbol mutate("#{@path}.#{key}") when Integer mutate("#{@path}[#{key}]") else raise ArgumentError end end |
#mutate(path) ⇒ Path
Mutates the path with the given path.
71 72 73 |
# File 'lib/web_function/promise.rb', line 71 def mutate(path) Path.new(path) end |
#to_json(*args) ⇒ String
Returns the JSON representation of the path.
44 45 46 |
# File 'lib/web_function/promise.rb', line 44 def to_json(*args) @path.to_json(*args) end |
#to_s ⇒ String
Returns the string representation of the path.
34 35 36 |
# File 'lib/web_function/promise.rb', line 34 def to_s @path end |