Class: ChronoForge::Executor::Context
- Inherits:
-
Object
- Object
- ChronoForge::Executor::Context
- Defined in:
- lib/chrono_forge/executor/context.rb
Defined Under Namespace
Classes: ValidationError
Constant Summary collapse
- ALLOWED_TYPES =
[ String, Integer, Float, TrueClass, FalseClass, NilClass, Hash, Array ]
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#fetch(key, default = nil) ⇒ Object
Fetches a value from the context Returns the value if the key exists, otherwise returns the default value.
-
#initialize(workflow) ⇒ Context
constructor
A new instance of Context.
- #key?(key) ⇒ Boolean
- #save! ⇒ Object
-
#set(key, value) ⇒ Object
Sets a value in the context Alias for the []= method.
-
#set_once(key, value) ⇒ Object
Sets a value in the context only if the key doesn’t already exist Returns true if the value was set, false otherwise.
Constructor Details
#initialize(workflow) ⇒ Context
Returns a new instance of Context.
17 18 19 20 21 |
# File 'lib/chrono_forge/executor/context.rb', line 17 def initialize(workflow) @workflow = workflow @context = workflow.context || {} @dirty = false end |
Instance Method Details
#[](key) ⇒ Object
27 28 29 |
# File 'lib/chrono_forge/executor/context.rb', line 27 def [](key) get_value(key) end |
#[]=(key, value) ⇒ Object
23 24 25 |
# File 'lib/chrono_forge/executor/context.rb', line 23 def []=(key, value) set_value(key, value) end |
#fetch(key, default = nil) ⇒ Object
Fetches a value from the context Returns the value if the key exists, otherwise returns the default value
33 34 35 |
# File 'lib/chrono_forge/executor/context.rb', line 33 def fetch(key, default = nil) key?(key) ? get_value(key) : default end |
#key?(key) ⇒ Boolean
52 53 54 |
# File 'lib/chrono_forge/executor/context.rb', line 52 def key?(key) @context.key?(key.to_s) end |
#save! ⇒ Object
56 57 58 59 60 61 |
# File 'lib/chrono_forge/executor/context.rb', line 56 def save! return unless @dirty @workflow.update_column(:context, @context) @dirty = false end |
#set(key, value) ⇒ Object
Sets a value in the context Alias for the []= method
39 40 41 |
# File 'lib/chrono_forge/executor/context.rb', line 39 def set(key, value) set_value(key, value) end |
#set_once(key, value) ⇒ Object
Sets a value in the context only if the key doesn’t already exist Returns true if the value was set, false otherwise
45 46 47 48 49 50 |
# File 'lib/chrono_forge/executor/context.rb', line 45 def set_once(key, value) return false if key?(key) set_value(key, value) true end |