Sha256: b0c3013467e4f042c063cadf7ee38aa7a739f689e068c7c672552420f7beda10
Contents?: true
Size: 1.17 KB
Versions: 11
Compression:
Stored size: 1.17 KB
Contents
# frozen_string_literal: true module Floe class Workflow class ReferencePath < Path class << self def set(payload, context, value) new(payload).set(context, value) end end def initialize(*) require "more_core_extensions/core_ext/hash/nested" require "more_core_extensions/core_ext/array/nested" super raise Floe::InvalidWorkflowError, "Invalid Reference Path" if payload.match?(/@|,|:|\?/) end def set(context, value) result = context.dup path = JsonPath.new(payload) .path[1..] .map { |v| v.match(/\[(?<name>.+)\]/)["name"] } .map { |v| v[0] == "'" ? v.delete("'") : v.to_i } .compact # If the payload is '$' then merge the value into the context # otherwise use store path to set the value to a sub-key # # TODO: how to handle non-hash values, raise error if path=$ and value not a hash? if path.empty? result.merge!(value) else result.store_path(path, value) end result end end end end
Version data entries
11 entries across 11 versions & 1 rubygems