Class: NextStation::Result::Success
- Inherits:
-
NextStation::Result
- Object
- NextStation::Result
- NextStation::Result::Success
- Defined in:
- lib/next_station/result.rb
Overview
Represents a successful operation result.
Instance Method Summary collapse
-
#initialize(value, schema: nil, enforced: false) ⇒ Success
constructor
A new instance of Success.
- #success? ⇒ Boolean
- #value ⇒ Object
Methods inherited from NextStation::Result
Constructor Details
#initialize(value, schema: nil, enforced: false) ⇒ Success
Returns a new instance of Success.
41 42 43 44 45 46 |
# File 'lib/next_station/result.rb', line 41 def initialize(value, schema: nil, enforced: false) @raw_value = value @schema = schema @enforced = enforced @validated_value = nil end |
Instance Method Details
#success? ⇒ Boolean
62 63 64 |
# File 'lib/next_station/result.rb', line 62 def success? true end |
#value ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/next_station/result.rb', line 48 def value if @enforced && @schema.nil? raise NextStation::Error, 'Result schema enforcement is enabled but no result_schema is defined.' end return @raw_value unless @enforced && @schema @value ||= begin @schema.new(@raw_value) rescue StandardError => e raise NextStation::ResultShapeError, e. end end |