Class: Dry::Logic::Result
- Inherits:
-
Object
- Object
- Dry::Logic::Result
- Includes:
- Core::Constants
- Defined in:
- lib/dry/logic/result.rb
Constant Summary collapse
- SUCCESS =
Class.new { def success? true end def failure? false end }.new.freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
- #ast(input = Undefined) ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(success, id = nil, &block) ⇒ Result
constructor
A new instance of Result.
- #success? ⇒ Boolean
- #to_ast ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(success, id = nil, &block) ⇒ Result
Returns a new instance of Result.
24 25 26 27 28 |
# File 'lib/dry/logic/result.rb', line 24 def initialize(success, id = nil, &block) @success = success @id = id @serializer = block end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
20 21 22 |
# File 'lib/dry/logic/result.rb', line 20 def id @id end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
22 23 24 |
# File 'lib/dry/logic/result.rb', line 22 def serializer @serializer end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
18 19 20 |
# File 'lib/dry/logic/result.rb', line 18 def success @success end |
Instance Method Details
#ast(input = Undefined) ⇒ Object
42 43 44 |
# File 'lib/dry/logic/result.rb', line 42 def ast(input = Undefined) serializer.(input) end |
#failure? ⇒ Boolean
34 35 36 |
# File 'lib/dry/logic/result.rb', line 34 def failure? !success? end |
#success? ⇒ Boolean
30 31 32 |
# File 'lib/dry/logic/result.rb', line 30 def success? success end |
#to_ast ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/dry/logic/result.rb', line 46 def to_ast if id [type, [id, ast]] else ast end end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/dry/logic/result.rb', line 54 def to_s visit(to_ast) end |
#type ⇒ Object
38 39 40 |
# File 'lib/dry/logic/result.rb', line 38 def type success? ? :success : :failure end |