Sha256: a3dfe40e1722de87fba981281e006d6f5171f16c37aed0e257d621b48e5fbf89

Contents?: true

Size: 865 Bytes

Versions: 2

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

module Floe
  class Workflow
    class Path
      class << self
        def value(payload, context, input = {})
          new(payload).value(context, input)
        end
      end

      def initialize(payload)
        @payload = payload

        raise Floe::InvalidWorkflowError, "Path [#{payload}] must be a string" if payload.nil? || !payload.kind_of?(String)
        raise Floe::InvalidWorkflowError, "Path [#{payload}] must start with \"$\"" if payload[0] != "$"
      end

      def value(context, input = {})
        obj, path =
          if payload.start_with?("$$")
            [context, payload[1..]]
          else
            [input, payload]
          end

        results = JsonPath.on(obj, path)

        results.count < 2 ? results.first : results
      end

      private

      attr_reader :payload
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
floe-0.6.1 lib/floe/workflow/path.rb
floe-0.6.0 lib/floe/workflow/path.rb