Class: Yuriita::Result
- Inherits:
-
Object
- Object
- Yuriita::Result
- Defined in:
- lib/yuriita/result.rb
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(relation: nil, exception: nil) ⇒ Result
constructor
A new instance of Result.
- #successful? ⇒ Boolean
Constructor Details
#initialize(relation: nil, exception: nil) ⇒ Result
Returns a new instance of Result.
13 14 15 16 17 18 19 20 |
# File 'lib/yuriita/result.rb', line 13 def initialize(relation: nil, exception: nil) @relation = relation @exception = exception if @relation.nil? && @exception.nil? raise ArgumentError, "Must provide a relation or an exception" end end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
11 12 13 |
# File 'lib/yuriita/result.rb', line 11 def exception @exception end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
11 12 13 |
# File 'lib/yuriita/result.rb', line 11 def relation @relation end |
Class Method Details
.error(exception) ⇒ Object
3 4 5 |
# File 'lib/yuriita/result.rb', line 3 def self.error(exception) new(exception: exception) end |
.success(relation) ⇒ Object
7 8 9 |
# File 'lib/yuriita/result.rb', line 7 def self.success(relation) new(relation: relation) end |
Instance Method Details
#successful? ⇒ Boolean
22 23 24 |
# File 'lib/yuriita/result.rb', line 22 def successful? exception.nil? end |