Class: Floe::Workflow::ReferencePath
- Defined in:
- lib/floe/workflow/reference_path.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Path
Instance Method Summary collapse
- #get(context) ⇒ Object
-
#initialize ⇒ ReferencePath
constructor
A new instance of ReferencePath.
- #set(context, value) ⇒ Object
Methods inherited from Path
Constructor Details
#initialize ⇒ ReferencePath
Returns a new instance of ReferencePath.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/floe/workflow/reference_path.rb', line 8 def initialize(*) super raise Floe::InvalidWorkflowError, "Invalid Reference Path" if payload.match?(/@|,|:|\?/) @path = JsonPath.new(payload) .path[1..] .map { |v| v.match(/\[(?<name>.+)\]/)["name"] } .filter_map { |v| v[0] == "'" ? v.delete("'") : v.to_i } end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/floe/workflow/reference_path.rb', line 6 def path @path end |
Instance Method Details
#get(context) ⇒ Object
19 20 21 22 23 |
# File 'lib/floe/workflow/reference_path.rb', line 19 def get(context) return context if path.empty? context.dig(*path) end |
#set(context, value) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/floe/workflow/reference_path.rb', line 25 def set(context, value) result = context.dup # If the payload is '$' then replace the output with the value if path.empty? result = value.dup else child = result keys = path.dup last_key = keys.pop keys.each do |key| child[key] = {} if child[key].nil? child = child[key] end child[last_key] = value end result end |