class HumanistErrors::Search

Attributes

error_object[R]
found_error[R]
ruby_error_message[R]

Public Class Methods

new(error_object, ruby_error_message) click to toggle source
# File lib/humanist_errors/search.rb, line 9
def initialize(error_object, ruby_error_message)
  @error_object = error_object
  @ruby_error_message = ruby_error_message
end
run(error_object, ruby_error_message) click to toggle source
# File lib/humanist_errors/search.rb, line 4
def self.run(error_object, ruby_error_message)
  searcher = new(error_object, ruby_error_message)
  searcher.find
end

Public Instance Methods

find() click to toggle source
# File lib/humanist_errors/search.rb, line 14
def find
  error = keyify(error_object)
  return :no_result unless ERROR_MAPPER[error]
  ERROR_MAPPER[error][ruby_error_message]
end

Private Instance Methods

keyify(error) click to toggle source

turn a CamelCase word into an underscored symbol to make it nice for hash keys. Basically the same as ActiveSupport#underscore

# File lib/humanist_errors/search.rb, line 27
def keyify(error)
  error.to_s
    .gsub(/::/, '__')
    .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
    .gsub(/([a-z\d])([A-Z])/,'\1_\2')
    .tr("-", "_")
    .downcase
    .to_sym
end