class ExceptionHandler::Config

Constants

DEFAULTS

> Defaults

> stackoverflow.com/a/8917301/1143732

SOCIAL

> Social URLs

> Extracted from “social” block

TABLE

> Table Name

> Has to be “errors” because “exceptions” is a reserved word

Attributes

custom_exceptions[RW]

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts -> will need to be deprecated

> ExceptionHandler.config.exceptions

> ExceptionHandler.config.custom_exceptions

db[RW]

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts -> will need to be deprecated

> ExceptionHandler.config.exceptions

> ExceptionHandler.config.custom_exceptions

dev[RW]

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts -> will need to be deprecated

> ExceptionHandler.config.exceptions

> ExceptionHandler.config.custom_exceptions

email[RW]

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts -> will need to be deprecated

> ExceptionHandler.config.exceptions

> ExceptionHandler.config.custom_exceptions

exceptions[RW]

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts -> will need to be deprecated

> ExceptionHandler.config.exceptions

> ExceptionHandler.config.custom_exceptions

layouts[RW]

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts -> will need to be deprecated

> ExceptionHandler.config.exceptions

> ExceptionHandler.config.custom_exceptions

social[RW]

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts -> will need to be deprecated

> ExceptionHandler.config.exceptions

> ExceptionHandler.config.custom_exceptions

Public Class Methods

new(values) click to toggle source

> Constructor

> Merges DEFAULTS to values, creates instances vars (for attr_accessor)

# File lib/exception_handler/config.rb, line 134
def initialize values

  # => Vars
  DEFAULTS.deep_merge!(values || {}).each do |k,v|
    instance_variable_set("@#{k}",v)
  end

  # => Validation
  raise ExceptionHandler::Error, "Email Not Valid" if @email && !@email.nil? && !@email.is_a?(String)
  raise ExceptionHandler::Error, "Migration Required → \"#{db}\" doesn't exist" if @db && !ActiveRecord::Base.connection.table_exists?(db) && (File.basename($0) != "rake" && !ARGV.include?("db:migrate"))

end

Public Instance Methods

options(status, pluck=nil) click to toggle source

> Options

> Requires argument

# File lib/exception_handler/config.rb, line 161
def options status, pluck=nil

  # => Structure from old + new setup
  # => 1. layouts    => [500, '500']
  # => 2. exceptions => [500, '500' 'all', '4xx'/'5xx']
  { layouts:    [status, status.to_s], # old + new
    exceptions: [status, status.to_s, 'all', status.to_s.first + 'xx'] }.each do |key,array|

    # => Array
    # => https://stackoverflow.com/a/26877095/1143732
    array.each do |specific|
      item = self.send(key).try(:[], specific)
      return (item.is_a?(Hash) ? ActiveSupport::HashWithIndifferentAccess.new(item)[pluck.try(:to_sym)] : item) if item.present? || (self.send(key).try(:has_key?, specific) && item.nil?) #if result exists and it has a value (including nil)
    end

  end
end