Class: DevSuite::Workflow::StepContext

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_suite/workflow/step_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}, **options) ⇒ StepContext

Returns a new instance of StepContext.



8
9
10
11
# File 'lib/dev_suite/workflow/step_context.rb', line 8

def initialize(data = {}, **options)
  @data = data
  @store = create_store(options)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/dev_suite/workflow/step_context.rb', line 6

def data
  @data
end

#storeObject (readonly)

Returns the value of attribute store.



6
7
8
# File 'lib/dev_suite/workflow/step_context.rb', line 6

def store
  @store
end

Instance Method Details

#clearObject

Clear the context data



33
34
35
# File 'lib/dev_suite/workflow/step_context.rb', line 33

def clear
  @data.clear # Reset the context data
end

#get(key) ⇒ Object

Retrieve data by key



28
29
30
# File 'lib/dev_suite/workflow/step_context.rb', line 28

def get(key)
  Utils::Data.get_value_by_path(@data, key)
end

#set(key, value) ⇒ Object

Set data by key



23
24
25
# File 'lib/dev_suite/workflow/step_context.rb', line 23

def set(key, value)
  Utils::Data.set_value_by_path(@data, key, value)
end

#update(new_data) ⇒ Object

Update the context with new data



14
15
16
17
18
19
20
# File 'lib/dev_suite/workflow/step_context.rb', line 14

def update(new_data)
  unless new_data.is_a?(Hash) || new_data.is_a?(Array)
    raise ArgumentError, "New data must be a Hash"
  end

  Utils::Data.deep_merge!(@data, new_data)
end