Class: AmazingActivist::Outcome::Failure
- Inherits:
-
Object
- Object
- AmazingActivist::Outcome::Failure
- Defined in:
- lib/amazing_activist/outcome/failure.rb
Instance Attribute Summary collapse
- #activity ⇒ AmazingActivist::Base readonly
- #code ⇒ Symbol readonly
- #context ⇒ Hash readonly
- #exception ⇒ Exception? readonly
Instance Method Summary collapse
- #deconstruct ⇒ Array
- #deconstruct_keys(keys) ⇒ Hash
- #failure? ⇒ false
-
#initialize(code, activity:, message:, exception:, context:) ⇒ Failure
constructor
A new instance of Failure.
-
#message ⇒ String
Failure message.
- #success? ⇒ true
- #unwrap! ⇒ Object
- #value_or {|self| ... } ⇒ Object
Constructor Details
#initialize(code, activity:, message:, exception:, context:) ⇒ Failure
Returns a new instance of Failure.
26 27 28 29 30 31 32 |
# File 'lib/amazing_activist/outcome/failure.rb', line 26 def initialize(code, activity:, message:, exception:, context:) @code = code.to_sym @activity = activity @message = &.to_s @exception = exception @context = context end |
Instance Attribute Details
#activity ⇒ AmazingActivist::Base (readonly)
13 14 15 |
# File 'lib/amazing_activist/outcome/failure.rb', line 13 def activity @activity end |
#code ⇒ Symbol (readonly)
10 11 12 |
# File 'lib/amazing_activist/outcome/failure.rb', line 10 def code @code end |
#context ⇒ Hash (readonly)
19 20 21 |
# File 'lib/amazing_activist/outcome/failure.rb', line 19 def context @context end |
#exception ⇒ Exception? (readonly)
16 17 18 |
# File 'lib/amazing_activist/outcome/failure.rb', line 16 def exception @exception end |
Instance Method Details
#deconstruct ⇒ Array
46 47 48 |
# File 'lib/amazing_activist/outcome/failure.rb', line 46 def deconstruct [:failure, @code, @activity] end |
#deconstruct_keys(keys) ⇒ Hash
52 53 54 55 56 57 |
# File 'lib/amazing_activist/outcome/failure.rb', line 52 def deconstruct_keys(keys) deconstructed = { failure: @code, activity: @activity, exception: exception, context: context } deconstructed[:message] = if keys.nil? || keys.include?(:message) deconstructed end |
#failure? ⇒ false
40 41 42 |
# File 'lib/amazing_activist/outcome/failure.rb', line 40 def failure? true end |
#message ⇒ String
Failure message.
72 73 74 |
# File 'lib/amazing_activist/outcome/failure.rb', line 72 def @message || Polyglot.new(@activity).(@code, **context) end |
#success? ⇒ true
35 36 37 |
# File 'lib/amazing_activist/outcome/failure.rb', line 35 def success? false end |
#unwrap! ⇒ Object
65 66 67 |
# File 'lib/amazing_activist/outcome/failure.rb', line 65 def unwrap! raise UnwrapError, self end |
#value_or {|self| ... } ⇒ Object
60 61 62 |
# File 'lib/amazing_activist/outcome/failure.rb', line 60 def value_or yield self end |