Class: DevSuite::Workflow::StepContext
- Inherits:
-
Object
- Object
- DevSuite::Workflow::StepContext
- Defined in:
- lib/dev_suite/workflow/step_context.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear the context data.
-
#get(key) ⇒ Object
Retrieve data by key.
-
#initialize(data = {}, **options) ⇒ StepContext
constructor
A new instance of StepContext.
-
#set(key, value) ⇒ Object
Set data by key.
-
#update(new_data) ⇒ Object
Update the context with new data.
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 = {}, **) @data = data @store = create_store() end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/dev_suite/workflow/step_context.rb', line 6 def data @data end |
#store ⇒ Object (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
#clear ⇒ Object
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 |