Class: AmazingActivist::Outcome::Failure

Inherits:
Object
  • Object
show all
Defined in:
lib/amazing_activist/outcome/failure.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, activity:, message:, exception:, context:) ⇒ Failure

Returns a new instance of Failure.

Parameters:

  • code (#to_sym)
  • activity (AmazingActivist::Activity)
  • message (#to_s, nil)
  • exception (Exception, nil)
  • context (Hash)


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   = message&.to_s
  @exception = exception
  @context   = context
end

Instance Attribute Details

#activityAmazingActivist::Base (readonly)



13
14
15
# File 'lib/amazing_activist/outcome/failure.rb', line 13

def activity
  @activity
end

#codeSymbol (readonly)

Returns:

  • (Symbol)


10
11
12
# File 'lib/amazing_activist/outcome/failure.rb', line 10

def code
  @code
end

#contextHash (readonly)

Returns:

  • (Hash)


19
20
21
# File 'lib/amazing_activist/outcome/failure.rb', line 19

def context
  @context
end

#exceptionException? (readonly)

Returns:

  • (Exception, nil)


16
17
18
# File 'lib/amazing_activist/outcome/failure.rb', line 16

def exception
  @exception
end

Instance Method Details

#deconstructArray

Returns:

  • (Array)


46
47
48
# File 'lib/amazing_activist/outcome/failure.rb', line 46

def deconstruct
  [:failure, @code, @activity]
end

#deconstruct_keys(keys) ⇒ Hash

Returns:

  • (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] = message if keys.nil? || keys.include?(:message)

  deconstructed
end

#failure?false

Returns:

  • (false)


40
41
42
# File 'lib/amazing_activist/outcome/failure.rb', line 40

def failure?
  true
end

#messageString

Failure message.

Returns:

  • (String)


72
73
74
# File 'lib/amazing_activist/outcome/failure.rb', line 72

def message
  @message || Polyglot.new(@activity).message(@code, **context)
end

#success?true

Returns:

  • (true)


35
36
37
# File 'lib/amazing_activist/outcome/failure.rb', line 35

def success?
  false
end

#unwrap!Object

Raises:



65
66
67
# File 'lib/amazing_activist/outcome/failure.rb', line 65

def unwrap!
  raise UnwrapError, self
end

#value_or {|self| ... } ⇒ Object

Yield Parameters:

  • self (self)


60
61
62
# File 'lib/amazing_activist/outcome/failure.rb', line 60

def value_or
  yield self
end