exception_handler 0.4.7 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -1
  4. data/Gemfile +1 -1
  5. data/README.md +241 -92
  6. data/app/controllers/exception_handler/exception_controller.rb +13 -44
  7. data/app/helpers/exception_handler/application_helper.rb +47 -23
  8. data/app/models/exception_handler/error.rb +10 -9
  9. data/app/services/exception_handler/exception.rb +34 -0
  10. data/app/views/exception_handler/exception/show.html.erb +9 -6
  11. data/app/views/layouts/exception.html.erb +3 -3
  12. data/config/locales/en.yml +9 -0
  13. data/exception_handler.gemspec +16 -6
  14. data/lib/exception_handler.rb +67 -32
  15. data/lib/exception_handler/config.rb +49 -46
  16. data/lib/exception_handler/parse.rb +17 -17
  17. data/lib/exception_handler/parser/data.rb +57 -51
  18. data/lib/exception_handler/parser/ignore.rb +23 -23
  19. data/lib/exception_handler/version.rb +1 -1
  20. data/lib/generators/exception_handler/migration_generator.rb +17 -17
  21. data/lib/generators/exception_handler/views_generator.rb +27 -27
  22. data/spec/database.yml +3 -0
  23. data/spec/dummy/Rakefile +6 -0
  24. data/spec/dummy/app/assets/config/manifest.js +4 -0
  25. data/spec/dummy/app/assets/images/.keep +0 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  27. data/spec/dummy/app/assets/javascripts/cable.coffee +11 -0
  28. data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
  29. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  30. data/spec/dummy/app/channels/application_cable/channel.rb +5 -0
  31. data/spec/dummy/app/channels/application_cable/connection.rb +5 -0
  32. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  33. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  34. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  35. data/spec/dummy/app/jobs/application_job.rb +2 -0
  36. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  37. data/spec/dummy/app/models/application_record.rb +3 -0
  38. data/spec/dummy/app/models/concerns/.keep +0 -0
  39. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  40. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  41. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  42. data/spec/dummy/bin/bundle +3 -0
  43. data/spec/dummy/bin/rails +4 -0
  44. data/spec/dummy/bin/rake +4 -0
  45. data/spec/dummy/bin/setup +34 -0
  46. data/spec/dummy/bin/update +29 -0
  47. data/spec/dummy/config.ru +8 -0
  48. data/spec/dummy/config/application.rb +21 -0
  49. data/spec/dummy/config/boot.rb +5 -0
  50. data/spec/dummy/config/cable.yml +10 -0
  51. data/spec/dummy/config/database.yml +25 -0
  52. data/spec/dummy/config/environment.rb +5 -0
  53. data/spec/dummy/config/environments/development.rb +62 -0
  54. data/spec/dummy/config/environments/production.rb +87 -0
  55. data/spec/dummy/config/environments/test.rb +42 -0
  56. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -0
  57. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  58. data/spec/dummy/config/initializers/assets.rb +11 -0
  59. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/spec/dummy/config/initializers/callback_terminator.rb +6 -0
  61. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  62. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  63. data/spec/dummy/config/initializers/inflections.rb +16 -0
  64. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  65. data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +4 -0
  66. data/spec/dummy/config/initializers/request_forgery_protection.rb +4 -0
  67. data/spec/dummy/config/initializers/session_store.rb +3 -0
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  69. data/spec/dummy/config/locales/en.yml +23 -0
  70. data/spec/dummy/config/puma.rb +47 -0
  71. data/spec/dummy/config/routes.rb +6 -0
  72. data/spec/dummy/config/secrets.yml +22 -0
  73. data/spec/dummy/lib/assets/.keep +0 -0
  74. data/spec/dummy/log/.keep +0 -0
  75. data/spec/dummy/public/404.html +67 -0
  76. data/spec/dummy/public/422.html +67 -0
  77. data/spec/dummy/public/500.html +66 -0
  78. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  79. data/spec/dummy/public/apple-touch-icon.png +0 -0
  80. data/spec/dummy/public/favicon.ico +0 -0
  81. data/spec/exception_handler.rb +22 -0
  82. data/spec/helpers/exception_handler/application_helper_spec.rb +42 -0
  83. data/spec/spec_helper.rb +28 -9
  84. metadata +102 -39
  85. data/readme/400.jpg +0 -0
  86. data/readme/500.jpg +0 -0
  87. data/readme/application_controller.jpg +0 -0
  88. data/readme/config.jpg +0 -0
  89. data/readme/db.jpg +0 -0
  90. data/readme/db_edit.jpg +0 -0
  91. data/readme/dev.jpg +0 -0
  92. data/readme/exception_controller.jpg +0 -0
  93. data/readme/exceptions_app.png +0 -0
  94. data/readme/layout.jpg +0 -0
  95. data/readme/parser.jpg +0 -0
  96. data/readme/rubygems.jpg +0 -0
  97. data/readme/source/screen.psd +0 -0
  98. data/readme/source/subtitle.psd +0 -0
  99. data/readme/source/title.psd +0 -0
  100. data/readme/subtitle.jpg +0 -0
  101. data/readme/title.jpg +0 -0
  102. data/readme/titles/bugs.png +0 -0
  103. data/readme/titles/contents.png +0 -0
  104. data/readme/titles/contribution.png +0 -0
  105. data/readme/titles/custom_error_pages.png +0 -0
  106. data/readme/titles/support.png +0 -0
  107. data/readme/titles/testing.png +0 -0
  108. data/readme/titles/title.psd +0 -0
  109. data/readme/view.jpg +0 -0
@@ -2,34 +2,26 @@ module ExceptionHandler
2
2
  class ExceptionController < ApplicationController
3
3
 
4
4
  #Response
5
+ #http://www.justinweiss.com/articles/respond-to-without-all-the-pain/
5
6
  respond_to :html, :xml, :json
6
7
 
7
- #Dependencies
8
- before_action :status, :app_details
9
-
10
8
  #Layout
11
- layout :layout_status
9
+ layout :layout
12
10
 
13
11
  #Helpers
14
- helper ExceptionHandler::ApplicationHelper #-> HELPERS http://stackoverflow.com/questions/9809787/why-is-my-rails-mountable-engine-not-loading-helper-methods-correctly
12
+ helper ExceptionHandler::Engine.helpers #-> HELPERS http://stackoverflow.com/questions/9809787/why-is-my-rails-mountable-engine-not-loading-helper-methods-correctly
15
13
  include Rails.application.routes.url_helpers #-> ROUTES http://stackoverflow.com/a/6074911/1143732
16
14
 
17
15
  ####################
18
16
  # Action #
19
17
  ####################
20
18
 
21
- #Show
19
+ #Show
20
+ #Amend responses in tests
21
+ #Need to test validity of JSON responses etc
22
22
  def show
23
- @layout = self.send(:_layout)
24
- @message = (/^(5[0-9]{2})$/ !~ @status.to_s) ? "Sorry, this page is missing" : details[:message]
25
-
26
- ## Config "404 block" handler ##
27
- if /^(5[0-9]{2})$/ !~ @status.to_s && ExceptionHandler.config.layouts["404"] #-> http://www.justskins.com/forums/ruby-s-regexp-is-52846.html
28
- eval ExceptionHandler.config.layouts["404"]
29
- else
30
- ## Render (if eval do anything) ##
31
- render status: @status
32
- end
23
+ @exception = ExceptionHandler::Exception.new request #-> Service Object
24
+ render status: @exception.status #-> Show apppropriate response
33
25
  end
34
26
 
35
27
  ####################
@@ -38,23 +30,8 @@ module ExceptionHandler
38
30
 
39
31
  protected
40
32
 
41
- #Info
42
- def status
43
- @exception = env['action_dispatch.exception']
44
- @status = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
45
- @response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
46
- end
47
-
48
- #Format
49
- def details
50
- @details ||= {}.tap do |h|
51
- I18n.with_options scope: [:exception, :show, @response], exception_name: @exception.class.name, exception_message: @exception.message do |i18n|
52
- h[:name] = i18n.t "#{@exception.class.name.underscore}.title", default: i18n.t(:title, default: @exception.class.name)
53
- h[:message] = i18n.t "#{@exception.class.name.underscore}.description", default: i18n.t(:description, default: @exception.message)
54
- end
55
- end
56
- end
57
- helper_method :details
33
+ # Status declarations moved to "show" w/ service object
34
+ # Details moved to "View Helper"
58
35
 
59
36
  ####################
60
37
  # Layout #
@@ -63,19 +40,11 @@ module ExceptionHandler
63
40
  private
64
41
 
65
42
  #Layout
66
- def layout_status
67
- case @status
68
- when 404
69
- ExceptionHandler.config.layouts["400"] || nil #-> inherits ApplicationController layout
70
- else
71
- ExceptionHandler.config.layouts["500"] #-> should pull default if none sepecified
72
- end
43
+ def layout
44
+ (/^(5[0-9]{2})$/ !~ @exception.code.to_s) ? (ExceptionHandler.config.layouts["400"] || nil) : ExceptionHandler.config.layouts["500"] #-> if not 500, use predefined layout
73
45
  end
74
46
 
75
- #App
76
- def app_details
77
- @app_name = Rails.application.class.parent_name
78
- end
47
+ ####################
79
48
 
80
49
  end
81
50
  end
@@ -1,32 +1,56 @@
1
1
  module ExceptionHandler
2
- module ApplicationHelper
2
+ module ApplicationHelper
3
3
 
4
- #Refs
5
- #http://stackoverflow.com/a/5795683/1143732
6
- #http://stackoverflow.com/questions/8028021/helpers-in-rails-engine
7
- #ActiveSupport.on_load( :action_view ){ include ExceptionHandler::ViewHelpers }
4
+ ##################
8
5
 
9
- #Social
10
- def social *services
11
- output = []
12
- # options = args.extract_options! http://simonecarletti.com/blog/2009/09/inside-ruby-on-rails-extract_options-from-arrays/ - args for hash
6
+ #Refs
7
+ #http://stackoverflow.com/a/5795683/1143732
8
+ #http://stackoverflow.com/questions/8028021/helpers-in-rails-engine
9
+ #ActiveSupport.on_load( :action_view ){ include ExceptionHandler::ViewHelpers }
13
10
 
14
- services = ExceptionHandler.config.social unless services.any? #-> http://api.rubyonrails.org/classes/Hash.html#method-i-compact
15
- services.except(:url).compact.each do |service,username| #-> except http://stackoverflow.com/a/11105831/1143732
16
- output.push link_to(image_tag("exception_handler/connect/#{service}.png", title: "Find us on " + service.to_s.titleize), link(service), target: :blank, class: service.to_s)
17
- end
11
+ ##################
18
12
 
19
- output.join("").html_safe #-> ruby returns last line
20
- end
13
+ #App (Application name)
14
+ def app
15
+ Rails.application.class.parent_name
16
+ end
21
17
 
22
- private
18
+ #Details
19
+ def details
20
+ @details ||= {}.tap do |h|
21
+ I18n.with_options scope: [:exception, :show, @exception.response], message: @exception.message do |i18n|
22
+ h[:name] = i18n.t "#{@exception.class.name.underscore}.title", default: i18n.t(:title, default: @exception.class.name)
23
+ h[:description] = i18n.t "#{@exception.class.name.underscore}.description", default: i18n.t(:description, default: @exception.message)
24
+ end
25
+ end
26
+ end
23
27
 
24
- def link service #-> bloated way to allow single references in config
25
- url = []
26
- url.push ExceptionHandler.config.social[:url][service]
27
- url.push ExceptionHandler.config.social[service]
28
- url.join("/")
29
- end
28
+ #Social
29
+ def social *services
30
+ output = []
31
+ # options = args.extract_options! http://simonecarletti.com/blog/2009/09/inside-ruby-on-rails-extract_options-from-arrays/ - args for hash
30
32
 
31
- end
33
+ services = ExceptionHandler.config.social unless services.any? #-> http://api.rubyonrails.org/classes/Hash.html#method-i-compact
34
+ services.except(:url).compact.each do |service,username| #-> except http://stackoverflow.com/a/11105831/1143732
35
+ output.push link_to(image_tag("exception_handler/connect/#{service}.png", title: "Find us on " + service.to_s.titleize), link(service), target: :blank, class: service.to_s)
36
+ end
37
+
38
+ output.join("").html_safe #-> ruby returns last line
39
+ end
40
+
41
+
42
+ ##################
43
+
44
+ private
45
+
46
+ def link service #-> bloated way to allow single references in config
47
+ url = []
48
+ url.push ExceptionHandler.config.social[:url][service]
49
+ url.push ExceptionHandler.config.social[service]
50
+ url.join("/")
51
+ end
52
+
53
+ ##################
54
+
55
+ end
32
56
  end
@@ -1,13 +1,14 @@
1
1
  module ExceptionHandler
2
- class Error < ActiveRecord::Base
3
- #Table is called "errors"
4
- #Dev needs to use migration to create db
5
- def self.table_name
6
- ExceptionHandler.config.db
7
- end
2
+ class Error < ActiveRecord::Base
8
3
 
9
- #Associations
10
- belongs_to :usable, polymorphic: true
4
+ #Table is called "errors"
5
+ #Dev needs to use migration to create db
6
+ def self.table_name
7
+ ExceptionHandler.config.db
8
+ end
11
9
 
12
- end
10
+ #Associations
11
+ belongs_to :usable, polymorphic: true
12
+
13
+ end
13
14
  end
@@ -0,0 +1,34 @@
1
+ module ExceptionHandler
2
+ class Exception #-> https://www.netguru.co/blog/service-objects-in-rails-will-help
3
+ attr_reader :exception, :request, :class, :message
4
+
5
+ ######################
6
+
7
+ def initialize request
8
+ @request = request
9
+ @exception = request.env['action_dispatch.exception']
10
+
11
+ @class = @exception.class
12
+ @message = @exception.message
13
+ end
14
+
15
+ ######################
16
+
17
+ # Status code (404, 500 etc)
18
+ def code
19
+ ActionDispatch::ExceptionWrapper.new(@request.env, @exception).status_code
20
+ end
21
+
22
+ # Server Response ("Not Found" etc)
23
+ def response
24
+ ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
25
+ end
26
+
27
+ ######################
28
+
29
+ alias_method :status, :code #-> http://stackoverflow.com/a/11848832/1143732 (has to be below methods)
30
+
31
+ ######################
32
+
33
+ end
34
+ end
@@ -1,29 +1,32 @@
1
1
  <div class="error">
2
- <% if /^(5[0-9]{2})$/ =~ @status.to_s %>
2
+ <% if /^(5[0-9]{2})$/ =~ @exception.status.to_s %>
3
3
 
4
4
  <!--Message -->
5
5
  <%= content_tag :div, class: "message" do %>
6
6
  <%= content_tag :div, class: "title" do %>
7
- <span><%= "#{@status} Error - #{details[:name]}" %></span>
7
+ <span><%= "#{@exception.status} Error - #{details[:name]}" %></span>
8
8
  <%= link_to image_tag("exception_handler/close.png"), main_app.root_url, title: "Close (Go back home)", class: "close" %>
9
9
  <% end %>
10
+
10
11
  <%= content_tag :div, class: "details" do %>
11
- <%= image_tag "exception_handler/alert.png", title: "#{@status} Error" %>
12
- <div class="status"><%= @status %> Error</div>
12
+ <%= image_tag "exception_handler/alert.png", title: "#{@exception.status} Error" %>
13
+ <div class="status"><%= @exception.status %> Error</div>
13
14
  <% end %>
15
+
14
16
  <%= content_tag :div, class: "info" do %>
15
- <span><%= @message %></span>
17
+ <span><%= details[:description] %></span>
16
18
  <div class="notification">
17
19
  <%= link_to image_tag("exception_handler/home.png", title: "Go Back Home"), main_app.root_url, class: "home" %>
18
20
  <div class="version">v<%= Rails.version %></div>
19
21
  <strong>Our developers have been notified - we're working on it!</strong>
20
22
  </div>
21
23
  <% end %>
24
+
22
25
  <% end %>
23
26
 
24
27
  <% else %>
25
28
 
26
- <%= content_tag :div, @message, class: "message" %>
29
+ <%= content_tag :div, details[:description], class: "message" %>
27
30
 
28
31
  <% end %>
29
32
  </div>
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
 
5
5
  <!--Info -->
6
- <title><%= "Code #{@status} (#{details[:name]}) | #{@app_name.upcase}" %></title>
6
+ <title><%= "Error - #{@exception.status} Error (#{details[:name]})" %></title>
7
7
  <%= stylesheet_link_tag "exception_handler/error" %>
8
8
 
9
9
  </head>
@@ -20,8 +20,8 @@
20
20
  <%= social %>
21
21
  </div>
22
22
  <div class="app">
23
- <strong><%= link_to @app_name, main_app.root_url, title: "Go to index" %></strong>
24
- <span> - <%= @status %> Error</span>
23
+ <strong><%= link_to app, main_app.root_url, title: "Go to index" %></strong>
24
+ <span> - <%= @exception.status %> Error</span>
25
25
  </div>
26
26
  </footer>
27
27
 
@@ -0,0 +1,9 @@
1
+ en:
2
+ exception:
3
+ show:
4
+ not_found:
5
+ title: "Not Found"
6
+ description: "Sorry, this page is missing."
7
+ internal_server_error:
8
+ title: "Internal Server Error"
9
+ description: "Sorry, the server failed with the error: %{message}"
@@ -4,26 +4,36 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'exception_handler/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
+
8
+ # General
7
9
  s.name = "exception_handler"
8
10
  s.version = ExceptionHandler::VERSION
9
- s.authors = ["Richard Peck", "Joe Hilton"]
10
- s.email = ["rpeck@frontlineutilities.co.uk", "jhilton@frontlineutilities.co.uk"]
11
- s.summary = %q{Rails gem to show custom error pages in production. Also logs errors in "errors" db if required}
11
+ s.authors = ["Richard Peck"]
12
+ s.email = ["rpeck@frontlineutilities.co.uk"]
13
+ s.summary = %q{Rails gem to show custom error pages in production. Also logs errors in db & sends notification emails}
12
14
  s.description = %q{Rails gem to create custom error pages. Captures exceptions using "exception_app" callback, routing to "Exception" controller, rendering the view as required.}
13
- s.homepage = "http://frontlineutilities.co.uk/ror/custom_error_pages"
15
+ s.homepage = "http://github.com/richpeck/exception_handler"
14
16
  s.license = "MIT"
15
17
 
18
+ # Files
16
19
  s.files = `git ls-files -z`.split("\x0")
20
+ s.files.reject! { |fn| fn.include? "readme" } #-> https://github.com/gauntlt/gauntlt/blob/master/gauntlt.gemspec#L16
21
+
17
22
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
23
+ s.test_files = s.files.grep(%r{^(test|spec|features)/}) unless RUBY_VERSION >= "2.2.0" #-> deprecated in Ruby 2.2.0
19
24
  s.require_paths = ["lib"]
20
25
 
26
+ # Options
21
27
  s.post_install_message = File.read(File.join(File.dirname(__FILE__), 'post_install_message.md')) #-> https://github.com/jarrett/ichiban/blob/master/ichiban.gemspec#L35
22
28
 
29
+ # dev Dependencies
23
30
  s.add_development_dependency "bundler", "~> 1.6"
24
31
  s.add_development_dependency "rails", "~> 4.0.0"
25
32
  s.add_development_dependency "activerecord"
26
33
  s.add_development_dependency "activesupport"
27
34
  s.add_development_dependency "rake"
28
- s.add_development_dependency "rspec"
35
+ s.add_development_dependency "rspec", "~> 3.3"
36
+ s.add_development_dependency "rspec-rails", "~> 3.3"
37
+ s.add_development_dependency "sqlite3", "~> 1.3.10"
38
+
29
39
  end
@@ -13,41 +13,76 @@ Dir.glob(File.join(File.dirname(__FILE__), "exception_handler", '**/*.rb'), &met
13
13
 
14
14
  module ExceptionHandler
15
15
 
16
- #Version
17
- autoload :VERSION, 'exception_handler/version'
16
+ #Config
17
+ #Invoke instance of config (ExceptionHandler.config) -- loads defaults -- can merge through class
18
+ mattr_accessor :config
18
19
 
19
- #Config
20
- #Invoke instance of config -- loads defaults
21
- mattr_accessor :config
20
+ #Default (has to init so is available in all areas)
21
+ @@config = "" #-> should initialize class & then append in initializer
22
22
 
23
- # Don't have prefix method return anything.
23
+ # Class methods
24
+ class << self
25
+ # Don't have prefix method return anything.
24
26
  # This will keep Rails Engine from generating all table prefixes with the engines name
25
27
  # http://stackoverflow.com/questions/19435214/rails-mountable-engine-with-isolate-namespace-but-without-prefixed-namespace-on
26
- def self.table_name_prefix
27
- #No prefix
28
+ def table_name_prefix
29
+ #No prefix
28
30
  end
31
+ end
29
32
 
30
- #Exception Handler
31
- class Exceptions < Rails::Engine
32
- #Keep helpers in your engine
33
- #http://guides.rubyonrails.org/engines.html#inside-an-engine
34
- #http://stackoverflow.com/questions/31877839/accessing-helpers-from-the-parent-app-in-an-isolated-rails-engine
35
- #use main_app to call "main app" helpers etc http://stackoverflow.com/a/9178022/1143732 + http://edgeapi.rubyonrails.org/classes/Rails/Engine.html#class-Rails::Engine-label-Using+Engine-27s+routes+outside+Engine
36
- isolate_namespace ExceptionHandler
37
-
38
- #Stylesheet
39
- config.assets.precompile += %w(exception_handler/error.css)
40
-
41
- #Hook
42
- initializer "exception_handler.configure_rails_initialization" do |app|
43
-
44
- #Options
45
- ExceptionHandler.config = ExceptionHandler::Config.new(app.config.respond_to?(:exception_handler) ? app.config.exception_handler : nil)
46
-
47
- #Middleware
48
- app.config.middleware.use ExceptionHandler::Parse if ExceptionHandler.config.db # && ActiveRecord::Base.connection.table_exists?(:errors unless @@config[:db].blank?) #DB
49
- app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionController.action(:show).call(env) } #Controller
50
- end
51
-
52
- end
53
- end
33
+ #########################
34
+
35
+ #Exception Handler
36
+ class Engine < Rails::Engine
37
+ #Keep helpers in your engine
38
+ #http://guides.rubyonrails.org/engines.html#inside-an-engine
39
+ #http://stackoverflow.com/questions/31877839/accessing-helpers-from-the-parent-app-in-an-isolated-rails-engine
40
+ #use main_app to call "main app" helpers etc http://stackoverflow.com/a/9178022/1143732 + http://edgeapi.rubyonrails.org/classes/Rails/Engine.html#class-Rails::Engine-label-Using+Engine-27s+routes+outside+Engine
41
+ isolate_namespace ExceptionHandler
42
+
43
+ #Tests (generates dummy Rails app)
44
+ #http://stackoverflow.com/q/32082637/1143732 (ref in question)
45
+ config.generators do |g|
46
+ g.test_framework :rspec
47
+ end
48
+
49
+ #Assets
50
+ config.assets.precompile << %w(exception_handler/**)
51
+
52
+ #Config
53
+ config.before_initialize do |app|
54
+ ExceptionHandler.config = ExceptionHandler::Config.new app.config.try(:exception_handler) #-> Var
55
+ end
56
+
57
+ #Boot order:
58
+ #http://api.rubyonrails.org/classes/Rails/Application.html#class-Rails::Application-label-Booting+process
59
+ #1) require "config/boot.rb" to setup load paths
60
+ #2) require railties and engines
61
+ #3) Define Rails.application as "class MyApp::Application < Rails::Application"
62
+ #4) Run config.before_configuration callbacks
63
+ #5) Load config/environments/ENV.rb
64
+ #6) Run config.before_initialize callbacks
65
+ #7) Run Railtie#initializer defined by railties, engines and application.
66
+ # One by one, each engine sets up its load paths, routes and runs its config/initializers/* files.
67
+ #8) Custom Railtie#initializers added by railties, engines and applications are executed
68
+ #9) Build the middleware stack and run to_prepare callbacks
69
+ #10) Run config.before_eager_load and eager_load! if eager_load is true
70
+ #11) Run config.after_initialize callbacks
71
+
72
+ #Hook
73
+ #Needs to fire before better_errors (for dev)
74
+ initializer :exception_handler, before: "better_errors.configure_rails_initialization" do |app| #-> "before" ref - http://blog.carbonfive.com/2011/02/25/configure-your-gem-the-rails-way-with-railtie/ && http://apidock.com/rails/Rails/Initializable/Initializer/before - should degrade gracefully
75
+
76
+ #Action
77
+ app.config.middleware.use ExceptionHandler::Parse if ExceptionHandler.config.try(:db) #-> DB
78
+ app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionController.action(:show).call(env) } #-> Controller
79
+
80
+ #Dev
81
+ #Logic needed after initialize (app data)
82
+ app.config.consider_all_requests_local = false if Rails.env.development? and ExceptionHandler.config.try(:dev)
83
+ end
84
+
85
+ end
86
+ end
87
+
88
+ ###########################################