Class: Compel::Result
- Inherits:
-
Object
- Object
- Compel::Result
- Defined in:
- lib/compel/result.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(validator) ⇒ Result
constructor
A new instance of Result.
- #raise? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(validator) ⇒ Result
Returns a new instance of Result.
7 8 9 10 11 |
# File 'lib/compel/result.rb', line 7 def initialize(validator) @valid = validator.valid? @value = validator.serialize @errors = validator.serialize_errors end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/compel/result.rb', line 5 def errors @errors end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/compel/result.rb', line 5 def value @value end |
Instance Method Details
#raise? ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/compel/result.rb', line 17 def raise? if !valid? exception = InvalidObjectError.new exception.object = value raise exception, 'object has errors' end value end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/compel/result.rb', line 13 def valid? @valid end |