Class: Taski::Context
- Inherits:
-
Object
- Object
- Taski::Context
- Defined in:
- lib/taski/context.rb
Overview
Runtime context accessible from any task. Holds user-defined options and execution metadata. Context is immutable after creation - options cannot be modified during task execution.
Instance Attribute Summary collapse
-
#root_task ⇒ Object
readonly
Returns the value of attribute root_task.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#working_directory ⇒ Object
readonly
Returns the value of attribute working_directory.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Get a user-defined option value.
-
#fetch(key, default = nil) { ... } ⇒ Object
Get a user-defined option value with a default.
-
#initialize(options:, root_task:) ⇒ Context
constructor
A new instance of Context.
-
#key?(key) ⇒ Boolean
Check if a user-defined option key exists.
Constructor Details
#initialize(options:, root_task:) ⇒ Context
Returns a new instance of Context.
14 15 16 17 18 19 |
# File 'lib/taski/context.rb', line 14 def initialize(options:, root_task:) = .dup.freeze @root_task = root_task @started_at = Time.now @working_directory = Dir.pwd end |
Instance Attribute Details
#root_task ⇒ Object (readonly)
Returns the value of attribute root_task.
10 11 12 |
# File 'lib/taski/context.rb', line 10 def root_task @root_task end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
10 11 12 |
# File 'lib/taski/context.rb', line 10 def started_at @started_at end |
#working_directory ⇒ Object (readonly)
Returns the value of attribute working_directory.
10 11 12 |
# File 'lib/taski/context.rb', line 10 def working_directory @working_directory end |
Instance Method Details
#[](key) ⇒ Object?
Get a user-defined option value
24 25 26 |
# File 'lib/taski/context.rb', line 24 def [](key) [key] end |
#fetch(key, default = nil) { ... } ⇒ Object
Get a user-defined option value with a default
33 34 35 36 37 38 39 40 41 |
# File 'lib/taski/context.rb', line 33 def fetch(key, default = nil, &block) if .key?(key) [key] elsif block block.call else default end end |
#key?(key) ⇒ Boolean
Check if a user-defined option key exists
46 47 48 |
# File 'lib/taski/context.rb', line 46 def key?(key) .key?(key) end |