Class: Dry::Logic::Result
- Inherits:
-
Object
- Object
- Dry::Logic::Result
- 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.
22 23 24 25 26 |
# File 'lib/dry/logic/result.rb', line 22 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.
18 19 20 |
# File 'lib/dry/logic/result.rb', line 18 def id @id end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
20 21 22 |
# File 'lib/dry/logic/result.rb', line 20 def serializer @serializer end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
16 17 18 |
# File 'lib/dry/logic/result.rb', line 16 def success @success end |
Instance Method Details
#ast(input = Undefined) ⇒ Object
40 41 42 |
# File 'lib/dry/logic/result.rb', line 40 def ast(input = Undefined) serializer.(input) end |
#failure? ⇒ Boolean
32 33 34 |
# File 'lib/dry/logic/result.rb', line 32 def failure? !success? end |
#success? ⇒ Boolean
28 29 30 |
# File 'lib/dry/logic/result.rb', line 28 def success? success end |
#to_ast ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/dry/logic/result.rb', line 44 def to_ast if id [type, [id, ast]] else ast end end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/dry/logic/result.rb', line 52 def to_s visit(to_ast) end |
#type ⇒ Object
36 37 38 |
# File 'lib/dry/logic/result.rb', line 36 def type success? ? :success : :failure end |