Sha256: b52df8fd37c44f3acd21a92aa0f30ea4553af3786797f672df97b31036023eee

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Floe
  class Workflow
    class Context
      def initialize(context = nil, input: {})
        context = JSON.parse(context) if context.kind_of?(String)

        @context = context || {
          "Execution"    => {
            "Input" => input
          },
          "State"        => {},
          "States"       => [],
          "StateMachine" => {},
          "Task"         => {}
        }
      end

      def execution
        @context["Execution"]
      end

      def state
        @context["State"]
      end

      def state=(val)
        @context["State"] = val
      end

      def states
        @context["States"]
      end

      def state_machine
        @context["StateMachine"]
      end

      def task
        @context["Task"]
      end

      def [](key)
        @context[key]
      end

      def []=(key, val)
        @context[key] = val
      end

      def dig(*args)
        @context.dig(*args)
      end

      def to_h
        @context
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
floe-0.3.0 lib/floe/workflow/context.rb
floe-0.2.3 lib/floe/workflow/context.rb
floe-0.2.2 lib/floe/workflow/context.rb
floe-0.2.1 lib/floe/workflow/context.rb