Class: MovableInk::AWS::Errors::ExpectedError

Inherits:
Object
  • Object
show all
Defined in:
lib/movable_ink/aws/errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(error_class, message_patterns = []) ⇒ ExpectedError

Returns a new instance of ExpectedError.



14
15
16
17
18
# File 'lib/movable_ink/aws/errors.rb', line 14

def initialize(error_class, message_patterns = [])
  @error_class = error_class
  message_patterns.each { |pattern| raise StandardError.new("Invalid message pattern provided #{pattern.inspect}") unless pattern.class == Regexp }
  @message_patterns = message_patterns
end

Instance Method Details

#match?(exception) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/movable_ink/aws/errors.rb', line 20

def match?(exception)
  return false unless exception.class == @error_class
  return true if @message_patterns.length == 0
  @message_patterns.each {|pattern| return true if exception.message.match(pattern) }
  false
end