Class: Alchemrest::Result::Error

Inherits:
Alchemrest::Result show all
Defined in:
lib/alchemrest/result.rb

Instance Method Summary collapse

Methods inherited from Alchemrest::Result

Error, Ok, [], for, #transform, #unwrap_or_raise!, #unwrap_or_rescue

Constructor Details

#initialize(error) ⇒ Error

rubocop:disable Lint/MissingSuper



33
34
35
36
37
38
39
40
41
42
# File 'lib/alchemrest/result.rb', line 33

def initialize(error) # rubocop:disable Lint/MissingSuper
  case error
    when String
      self.error = Alchemrest::Error.new(error)
    when *Alchemrest.rescuable_exceptions
      self.error = error
    else
      raise ArgumentError, "Error must be a string or one of the types defined in Alchemrest.rescuable_exceptions"
  end
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
# File 'lib/alchemrest/result.rb', line 44

def ==(other)
  other.is_a?(Error) && other.error == error
end

#deconstructObject



52
53
54
# File 'lib/alchemrest/result.rb', line 52

def deconstruct
  [error]
end

#deconstruct_keys(_keys) ⇒ Object



56
57
58
# File 'lib/alchemrest/result.rb', line 56

def deconstruct_keys(_keys)
  { error: }
end

#ok?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/alchemrest/result.rb', line 48

def ok?
  false
end