Class: ExceptionHandler::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_handler/config.rb

Constant Summary collapse

TABLE =

> Table Name

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

:errors
SOCIAL =

> Social URLs

> Extracted from “social” block

{
  facebook: "https://facebook.com",
  twitter:  "https://twitter.com",
  youtube:  "https://youtube.com/user",
  linkedin: "https://linkedin.com/company",
  fusion:   "https://frontlinefusion.com"
}
DEFAULTS =
{
  dev:    nil, # => defaults to "false" for dev mode
  db:     nil, # => defaults to :errors if true, else use "table_name" / :table_name
  email:  nil, # => requires string email and ActionMailer
  social: {
    facebook: nil,
    twitter:  nil,
    youtube:  nil,
    linkedin: nil,
    fusion:   nil,
  },
  layouts: {
    # => nil inherits from ApplicationController
    # => 4xx errors should be nil
    # => 5xx errors should be "exception" but can be nil if explicitly defined
    500 => "exception",
    501 => "exception",
    502 => "exception",
    503 => "exception",
    504 => "exception",
    505 => "exception",
    507 => "exception",
    510 => "exception"
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Config

> Init

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



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/exception_handler/config.rb', line 76

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)
end

Instance Attribute Details

#custom_exceptionsObject

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts

> ExceptionHandler.config.custom_exceptions



19
20
21
# File 'lib/exception_handler/config.rb', line 19

def custom_exceptions
  @custom_exceptions
end

#dbObject

> DB

> If config db = “true”, use TABLE constant



19
20
21
# File 'lib/exception_handler/config.rb', line 19

def db
  @db
end

#devObject

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts

> ExceptionHandler.config.custom_exceptions



19
20
21
# File 'lib/exception_handler/config.rb', line 19

def dev
  @dev
end

#emailObject

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts

> ExceptionHandler.config.custom_exceptions



19
20
21
# File 'lib/exception_handler/config.rb', line 19

def email
  @email
end

#layoutsObject

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts

> ExceptionHandler.config.custom_exceptions



19
20
21
# File 'lib/exception_handler/config.rb', line 19

def layouts
  @layouts
end

#socialObject

> Instace Objects

> ExceptionHandler.config.dev

> ExceptionHandler.config.db

> ExceptionHandler.config.email

> ExceptionHandler.config.social

> ExceptionHandler.config.layouts

> ExceptionHandler.config.custom_exceptions



19
20
21
# File 'lib/exception_handler/config.rb', line 19

def social
  @social
end