Class: Operatic::Result
- Inherits:
-
Object
- Object
- Operatic::Result
- Defined in:
- lib/operatic/result.rb
Instance Attribute Summary collapse
- #data ⇒ Data readonly
Instance Method Summary collapse
-
#[](key) ⇒ anything
Convenience proxy to read the
keyfrom its #data object. -
#deconstruct ⇒ Array(self, Hash<Symbol, anything>)
Returns a tuple of self and #to_h allowing you to pattern match across both the result’s status and its data.
-
#deconstruct_keys(keys = nil) ⇒ Hash<Symbol, anything>
Pattern match against the result’s data via #to_h.
- #freeze ⇒ self
-
#initialize(data) ⇒ Result
constructor
A new instance of Result.
-
#method_missing(name, *args, **kwargs, &block) ⇒ Object
Forwards unknown methods to its #data object allowing convenience accessors defined via Data.define to be available directly on the Result.
- #respond_to? ⇒ Boolean
-
#to_h ⇒ Hash<Symbol, anything>
Convenience proxy to Data#to_h.
Constructor Details
#initialize(data) ⇒ Result
Returns a new instance of Result.
7 8 9 |
# File 'lib/operatic/result.rb', line 7 def initialize(data) @data = data end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
Forwards unknown methods to its #data object allowing convenience accessors defined via Data.define to be available directly on the Operatic::Result.
76 77 78 79 |
# File 'lib/operatic/result.rb', line 76 def method_missing(name, *args, **kwargs, &block) return data.public_send(name, *args, **kwargs, &block) if data.respond_to?(name) super end |
Instance Attribute Details
Instance Method Details
#[](key) ⇒ anything
Convenience proxy to read the key from its #data object.
16 17 18 |
# File 'lib/operatic/result.rb', line 16 def [](key) data[key] end |
#deconstruct ⇒ Array(self, Hash<Symbol, anything>)
Returns a tuple of self and #to_h allowing you to pattern match across both the result’s status and its data.
40 41 42 |
# File 'lib/operatic/result.rb', line 40 def deconstruct [self, to_h] end |
#deconstruct_keys(keys = nil) ⇒ Hash<Symbol, anything>
Pattern match against the result’s data via #to_h.
63 64 65 |
# File 'lib/operatic/result.rb', line 63 def deconstruct_keys(keys = nil) to_h end |
#freeze ⇒ self
68 69 70 71 |
# File 'lib/operatic/result.rb', line 68 def freeze data.freeze super end |
#respond_to? ⇒ Boolean
81 82 83 |
# File 'lib/operatic/result.rb', line 81 def respond_to?(...) super || data.respond_to?(...) end |
#to_h ⇒ Hash<Symbol, anything>
Convenience proxy to Data#to_h.
88 89 90 |
# File 'lib/operatic/result.rb', line 88 def to_h data.to_h end |