Class: Jet::Result
- Inherits:
-
Object
- Object
- Jet::Result
- Defined in:
- lib/jet/result.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
- #!=(other) ⇒ Object
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #at ⇒ Object
- #errors ⇒ Object
- #errors_at(*at) ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(success, output = nil, context = {}) ⇒ Result
constructor
A new instance of Result.
- #success? ⇒ Boolean
- #with(**context) ⇒ Object
Constructor Details
#initialize(success, output = nil, context = {}) ⇒ Result
Returns a new instance of Result.
17 18 19 20 21 |
# File 'lib/jet/result.rb', line 17 def initialize(success, output = nil, context = {}) @context = _context(context) @success = success ? true : false @output = output end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
15 16 17 |
# File 'lib/jet/result.rb', line 15 def context @context end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
15 16 17 |
# File 'lib/jet/result.rb', line 15 def output @output end |
Class Method Details
.failure(output = nil, context = {}) ⇒ Object
6 7 8 |
# File 'lib/jet/result.rb', line 6 def failure(output = nil, context = {}) new(false, output, context) end |
.success(output = nil, context = {}) ⇒ Object
10 11 12 |
# File 'lib/jet/result.rb', line 10 def success(output = nil, context = {}) new(true, output, context) end |
Instance Method Details
#!=(other) ⇒ Object
23 24 25 |
# File 'lib/jet/result.rb', line 23 def !=(other) !(self == other) end |
#==(other) ⇒ Object
27 28 29 30 |
# File 'lib/jet/result.rb', line 27 def ==(other) return output == other.output if other.is_a?(self.class) output == other end |
#[](key) ⇒ Object
32 33 34 |
# File 'lib/jet/result.rb', line 32 def [](key) @context[key] end |
#at ⇒ Object
36 37 38 |
# File 'lib/jet/result.rb', line 36 def at context.fetch(:at, []) end |
#errors ⇒ Object
40 41 42 |
# File 'lib/jet/result.rb', line 40 def errors context.fetch(:errors, []) end |
#errors_at(*at) ⇒ Object
44 45 46 |
# File 'lib/jet/result.rb', line 44 def errors_at(*at) at.flatten.yield_self { |a| errors.select { |e| e.at[0...a.size] == a } } end |
#failure? ⇒ Boolean
48 49 50 |
# File 'lib/jet/result.rb', line 48 def failure? !@success end |
#success? ⇒ Boolean
52 53 54 |
# File 'lib/jet/result.rb', line 52 def success? @success end |
#with(**context) ⇒ Object
56 57 58 |
# File 'lib/jet/result.rb', line 56 def with(**context) self.class.new(@success, @output, @context.merge(context)) end |