Sha256: 1c766a29e695fc8d5cc4f1b64ff839ddb9ca71c469f03b5a2c588a9d43cc77fb

Contents?: true

Size: 850 Bytes

Versions: 7

Compression:

Stored size: 850 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

      attr_reader :payload

      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
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
floe-0.11.3 lib/floe/workflow/path.rb
floe-0.11.0 lib/floe/workflow/path.rb
floe-0.10.0 lib/floe/workflow/path.rb
floe-0.9.0 lib/floe/workflow/path.rb
floe-0.7.1 lib/floe/workflow/path.rb
floe-0.8.0 lib/floe/workflow/path.rb
floe-0.7.0 lib/floe/workflow/path.rb