Class: RSchema::Result
- Inherits:
-
Object
- Object
- RSchema::Result
- Defined in:
- lib/rschema/result.rb
Overview
The return value when calling a schema
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(valid, value, error) ⇒ Result
constructor
A new instance of Result.
- #invalid? ⇒ Boolean
- #valid? ⇒ Boolean
- #value ⇒ Object
Constructor Details
#initialize(valid, value, error) ⇒ Result
Returns a new instance of Result.
24 25 26 27 28 29 |
# File 'lib/rschema/result.rb', line 24 def initialize(valid, value, error) @valid = valid @value = value @error = error freeze end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
44 45 46 |
# File 'lib/rschema/result.rb', line 44 def error @error end |
Class Method Details
.failure(error = nil) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rschema/result.rb', line 16 def self.failure(error = nil) if error.nil? NIL_FAILURE else new(false, nil, error) end end |
.success(value = nil) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/rschema/result.rb', line 8 def self.success(value = nil) if value.nil? NIL_SUCCESS else new(true, value, nil) end end |
Instance Method Details
#invalid? ⇒ Boolean
35 36 37 |
# File 'lib/rschema/result.rb', line 35 def invalid? !valid? end |
#valid? ⇒ Boolean
31 32 33 |
# File 'lib/rschema/result.rb', line 31 def valid? @valid end |