module YmlErrorResponder::YmlMapper

Constants

FILE_MASK

Attributes

errors_handlers[R]

Public Instance Methods

add_handler(handlers) click to toggle source
# File lib/yml_error_responder/yml_mapper.rb, line 49
def add_handler(handlers)
  @errors_handlers.merge!(handlers) if handlers.present?
end
error_defined?(error) click to toggle source
# File lib/yml_error_responder/yml_mapper.rb, line 13
def error_defined?(error)
  @errors_handlers.key?(error.class.to_s)
end
error_payload(error) click to toggle source
# File lib/yml_error_responder/yml_mapper.rb, line 9
def error_payload(error)
  @errors_handlers[error.class.to_s]
end
load!() click to toggle source
# File lib/yml_error_responder/yml_mapper.rb, line 17
def load!
  raise 'Configuration path is not set!' if YmlErrorResponder.configuration_path.blank?

  read_dir do |path|
    add_handler(load_handlers(path, path_to_namespace(path)))
  end
end
load_handlers(path, namespace) click to toggle source
# File lib/yml_error_responder/yml_mapper.rb, line 31
def load_handlers(path, namespace)
  YAML
    .load_file(path)
    .try(:transform_keys) do |key|
      namespace.blank? ? key.to_s.camelize : [namespace, key.to_s.camelize].join('::')
    end
end
path_to_namespace(path) click to toggle source
# File lib/yml_error_responder/yml_mapper.rb, line 39
def path_to_namespace(path)
  path.match(/#{YmlErrorResponder.configuration_path}([^.]*)\/(.*).yml/)
    .try(:[], 1)
    .try do |match|
      match.split('/')
      .map{|m| m.camelize}
      .join('::')
    end
end
read_dir() { |path| ... } click to toggle source
# File lib/yml_error_responder/yml_mapper.rb, line 25
def read_dir
  Dir[[YmlErrorResponder.configuration_path, FILE_MASK].join].each do |path|
    yield path
  end
end