Class: Sod::Context
- Inherits:
-
Object
show all
- Defined in:
- lib/sod/context.rb
Overview
Provides a sharable, read-only, context for commands and actions.
Constant Summary
collapse
- EMPTY =
new.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(**attributes) ⇒ Context
Returns a new instance of Context.
10
11
12
|
# File 'lib/sod/context.rb', line 10
def initialize **attributes
@attributes = attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
22
|
# File 'lib/sod/context.rb', line 22
def method_missing(name, *) = respond_to_missing?(name) ? attributes[name] : super
|
Class Method Details
.[] ⇒ Object
8
|
# File 'lib/sod/context.rb', line 8
def self.[](...) = new(...)
|
Instance Method Details
#[](override, fallback) ⇒ Object
14
15
16
17
18
|
# File 'lib/sod/context.rb', line 14
def [] override, fallback
override || public_send(fallback)
rescue NoMethodError
raise Error, "Invalid context. Override or fallback (#{fallback.inspect}) values are missing."
end
|
#to_h ⇒ Object
20
|
# File 'lib/sod/context.rb', line 20
def to_h = attributes.dup
|