exception_handler 0.7.0 → 0.7.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2211c69b2d0f6f0f398db88612aae4a8967dbb83
4
- data.tar.gz: 7d02292d53764231acdef24f5e286c099ae264d0
3
+ metadata.gz: ccc92609ab7af5a0f65736e1578aaef57b51a2d7
4
+ data.tar.gz: 1843d7a57a2551baa486a8579e60594eca2e2d5f
5
5
  SHA512:
6
- metadata.gz: 359b3813af909ae13cff91cdb3e83d8c88fa69f4e9f9f41aa95126b6a7f9e7becfa1676f930ffc1ae22d5ce51fa00fa92c8290201014dce0d2354d95e06f89ed
7
- data.tar.gz: 78f0f47a6d9095fce23ac62ccd7ad82ca3baac8440b25829d207376cfd293a923b4fe408ce481472b5f0810c5c32b741a1d8b1199fbe62a705f80ef28fd2a47e
6
+ metadata.gz: 0af19ea19133e86ad15a43f9324ee923ebdce75a7747543bd57f799ca16c8b14f0f24b81ce6ed144c8a6cd78169c2aa5e0b6c8bc5780af801bf1d169acc57fb9
7
+ data.tar.gz: 0740300edaa518daf6db9e133b75650684bdcaf3b276b84c7e4568b9fd61d5032d8d0c14c5037ceaa72998c58076d059a7970b2a2d8321dbd95c526cb8e4fddd
@@ -0,0 +1 @@
1
+ *.psd filter=lfs diff=lfs merge=lfs -text
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  <p align="center">
8
8
  <a href="http://badge.fury.io/rb/exception_handler"><img src="https://badge.fury.io/rb/exception_handler.svg" align="absmiddle"></a>
9
- <a href="http://rubygems.org/richpeck/exception_handler"><img src="http://ruby-gem-downloads-badge.herokuapp.com/exception_handler/0.5.1?type=total&color=brightgreen" align="absmiddle" /></a>
9
+ <a href="http://rubygems.org/gems/exception_handler"><img src="http://ruby-gem-downloads-badge.herokuapp.com/exception_handler/0.5.1?type=total&color=brightgreen" align="absmiddle" /></a>
10
10
  <a href="https://codeclimate.com/github/richpeck/exception_handler"><img src="https://codeclimate.com/github/richpeck/exception_handler/badges/gpa.svg" align="absmiddle"/></a>
11
11
  <a href="https://gemnasium.com/richpeck/exception_handler"><img src="https://gemnasium.com/richpeck/exception_handler.svg" align="absmiddle"></a>
12
12
  <a href='https://coveralls.io/github/richpeck/exception_handler?branch=master'><img src='https://coveralls.io/repos/github/richpeck/exception_handler/badge.svg?branch=master' alt='Coverage Status' align="absmiddle" /></a>
@@ -14,7 +14,7 @@
14
14
  </p>
15
15
 
16
16
  <p align="center">
17
- <strong><a href="#user-content-install">Install</a></strong> → <strong><a href="#user-content-config">Setup</a></strong> → <strong><a href="#user-content-support">Support</a></strong>
17
+ <strong><a href="#install">Install</a></strong> → <strong><a href="#config">Setup</a></strong> → <strong><a href="#support">Support</a></strong>
18
18
  </p>
19
19
 
20
20
  ---
@@ -38,11 +38,13 @@
38
38
  ---
39
39
 
40
40
  <p align="center">
41
- <img src="readme/05.jpg" title="Version 0.7.0" />
41
+ <img src="readme/rails.jpg" title="Version 0.7.5 Released Early 2017" />
42
42
  </p>
43
43
 
44
+ ---
45
+
44
46
  <p align="center">
45
- <img src="readme/titles/rails5.png" title="Fully Rails 5 Compatible" width="550" />
47
+ <img src="readme/titles/rails5.png" title="Fully Rails 5 Compatible" width="625" />
46
48
  </p>
47
49
 
48
50
  <p align="center">
@@ -52,22 +54,24 @@
52
54
  <img src="readme/check_02.png" height="22" title="Rails 4 & 5 Compatible" align="absmiddle" />&nbsp; <strong align="absmiddle">Fully Rails 4 & 5 Compatible</strong> &nbsp;
53
55
  </p>
54
56
 
55
- Brand new `controller` & `middleware` have made **`ExceptionHandler`** even more powerful & efficient. Now you can use `ExceptionHandler` with a single click → **plug and play** custom exception pages:
57
+ Brand new `controller` & `middleware` have made **`ExceptionHandler`** even more powerful & efficient. Now you can use `ExceptionHandler` with a [single click](#install) → **plug and play** custom exception pages:
56
58
 
57
59
  <p align="center">
58
60
  <br />
59
- <img src="readme/404.png" title="400 Errors" width="430" />
61
+ <img src="readme/400.png" title="400 Errors" width="430" />
60
62
  <img src="readme/500.png" title="500 Errors" width="430" />
61
63
  </p>
62
64
 
63
- With major upgrades to the backend, **ExceptionHandler [0.7.0][latest]** is the leading exception management solution for Rails 5:
65
+ <p align="center">For over 3 years, <strong>ExceptionHandler</strong> has provided production-level <strong>Rails</strong> exception handling for <strong>4xx</strong> and <strong>5xx</strong> errors:</p>
64
66
 
65
- <p align="center">
66
- <h3>Features</h3>
67
- Custom 500 Errors Layout || DB || Model || Config || Email || 400 Default Layout || Sprockets 4 || Custom Exceptions
68
- </p>
67
+ ![HTTP Error Codes][http_codes]
68
+
69
+ Since **browsers only read `4xx` & `5xx` error codes**, all Rails exceptions have to be inferred. Thus, `ExceptionHandler` simply has to manage how the `4xx` / `5xx` errors are passed to the browser.
70
+
71
+ Unlike other gems, **`ExceptionHandler` uses a custom [`controller`](app/controllers/exception_handler/exceptions_controller.rb) to build an [`@exception`](app/models/exception_handler/exception.rb) object**. This allows us to save the exception, email it or do anything else we may need. The gem has already been a massive success and we continue to actively maintain it.
72
+
73
+ Now you can try for yourself ...
69
74
 
70
- **ExceptionHandler works 100% with Rails 5 and Sprockets 4**. It hooks DIRECTLY into your existing CSS to create a professional exception interface with NO work on your part…
71
75
 
72
76
  ----
73
77
 
@@ -78,213 +82,266 @@ With major upgrades to the backend, **ExceptionHandler [0.7.0][latest]** is the
78
82
 
79
83
  The secret lies in [**`config.exceptions_app`**][exception_app] ↴
80
84
 
85
+ > **`config.exceptions_app`** sets the exceptions application invoked by the **`ShowException`** middleware when an exception happens. Defaults to **`ActionDispatch::PublicExceptions.new(Rails.public_path)`**
86
+
87
+ ![Exceptions handled by the ActiveDispatch::ShowExceptions Middleware][middleware]
88
+
89
+ Each time an exception is raised, [`ShowExceptions`][show_exception] takes the request and forwards it to `config.exceptions_app`. This is expected to return a response - allowing us to inject a [`controller`](app/controllers/exception_handler/exceptions_controller.rb):
90
+
91
+ > ```app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionsController.action(:show).call(env) }```
81
92
 
82
93
  ![config.exceptions_app - The key to all Rails exceptions][exceptions_app]
83
94
 
84
- Because we handle **`requests`** directly (`message`, `details`, `user agent`), `ExceptionHandler` populates our custom `view` with any details required. This gives us the ability to **maintain your branding** (layout / css) even when exceptions are raised:
95
+ Because our callback maintains the request, we are able to do whatever we need before serving a response. This is a **major** advantage over the "default" (routes). The routes invokes Rails twice and does not persist the request.
96
+
97
+ **`ExceptionHandler` is the only gem to provide middleware-powered exception handling.** It populates our custom `view` with details, giving us the ability to **maintain branding** when exceptions are raised:
85
98
 
86
99
  ![Exceptions handled by the ActiveDispatch::ShowExceptions Middleware][middleware]
87
100
 
88
- This is important at is means `ExceptionHandler` has absolutely ZERO bloat on an app. Rails is invoked ONCE (not twice like it is when using routes), delivering a response JUST LIKE if an exception wasn't raised.
101
+ **`ExceptionHandler` is the most EFFECTIVE and EFFICIENT gem to handle exceptions in Rails**.
89
102
 
90
- <p align="center">
91
- <strong>The <i>ONLY</i> professional solution to catch, process & handle Rails exceptions <i>WITHOUT</i> BLOAT:</strong>
103
+ Once invoked, its `model`, `controller` and `views` work together to serve the best responses to Rails errors ...
104
+
105
+ ----------
106
+
107
+ <p align="center" id="install">
108
+ <br />
109
+ <img src="readme/titles/install.png" title="1 Click Install for ExceptionHandler 0.7.0 on Rails 5" width="400" />
110
+ <br />
111
+ <strong>Custom Rails Error Pages - ZERO configuration needed:</strong>
112
+ <br />
92
113
  </p>
93
114
 
94
115
  <p align="center">
95
- <img src="readme/controller_middleware.jpg" title="ExceptionsController compiles the exception & delivers to the front-end" />
116
+ <a href="http://rubygems.org/gems/exception_handler"><img src="readme/gem.jpg" /></a> <a href="http://rubygems.org/gems/exception_handler"><img src="readme/gemfile.jpg" /></a>
96
117
  </p>
97
118
 
98
- The REAL beauty of ExceptionHandler is that you only have to serve **two** error responses → `400` & `500`. This is per the [HTTP spec](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4) - a browser CANNOT read any other form of error.
99
119
 
100
- This means that we can use a single controller action to build our `@exception` object, responding to the HTTP request with the status code raised by the exception. We have built this into a simple & effective solution:
120
+ <p align="center">
121
+ You can install it from the <strong>CLI</strong> or <strong>Gemfile</strong> - it will AUTOMATICALLY run in <strong>production</strong>.
122
+ <br />
123
+ <strong>↓ To run in development, use <a href="#dev-mode">dev mode</a> ↓</strong>
124
+ </p>
101
125
 
102
- ----------
126
+ ---
103
127
 
104
- <p align="center" id="install">
105
- <br />
106
- <img src="readme/titles/install.png" title="1 Click Install for ExceptionHandler 0.7.0 on Rails 5" width="400" />
128
+ <p align="center">
129
+ If you want to set it up your way, you can use these features...
130
+ </p>
131
+
132
+ <p align="center">
133
+ <a href="#config"><img src="readme/titles/icons/config.png" alt="Cinfiguration Options" align="absmiddle" height="24" /> Config</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#dev-mode" title="Dev Mode"><img src="readme/titles/icons/dev.png" alt="Dev" align="absmiddle" height="24" /> Dev</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#database"><img src="readme/titles/icons/database.png" alt="Database" align="absmiddle" height="24" /> Database</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#email"><img src="readme/titles/icons/email.png" alt="Email" align="absmiddle" height="24" /> Email</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#views"><img src="readme/titles/icons/views.png" alt="Views" align="absmiddle" height="24" /> Views</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#locales"><img src="readme/titles/icons/locales.png" alt="Locales" align="absmiddle" height="24" /> Locales</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#custom-exceptions"><img src="readme/titles/icons/custom.png" alt="Custom Exceptions" align="absmiddle" height="24" /> Custom Exceptions</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#generators"><img src="readme/titles/icons/generators.png" alt="Generators" align="absmiddle" height="24" /> Generators</a>
107
134
  </p>
108
135
 
109
- [![Gemfile][gemfile]][rubygems] [![Gem][gem]][rubygems]
136
+ ----
137
+
138
+ ## Config
139
+
140
+ **From [`0.4.7`](https://github.com/richpeck/exception_handler/releases/tag/0.4.6), `ExceptionHandler` manages its [config](lib/exception_handler/config.rb#L45) from the central Rails `config` hash:**
141
+
142
+ [![config][config]](lib/exception_handler/config.rb#L45)
110
143
 
111
- `ExceptionHandler`'s **config** system stores the - you just need to install the gem & let it run.
144
+ If you're using an [`engine`](http://guides.rubyonrails.org/engines.html), you don't need to use an `initializer`:
112
145
 
113
- If you want to change *any* settings (detailed [below](#user-content-config)), you **simply** need to change `config/application.rb` or `config/environments/your_env.rb`. The ***POWER*** of this *new config system* means you're able to deploy `ExceptionHandler` in the most unobtrusive, versatile way possible:
146
+ # lib/engine.rb
147
+ module YourModule
148
+ class Engine < Rails::Engine
149
+
150
+ # => ExceptionHandler
151
+ # => Works in and out of an initializer
152
+ config.exception_handler = {
153
+ dev: false,
154
+ db: true
155
+ }
156
+ end
157
+
158
+ end
159
+
160
+ You only need to provide the inputs you want, for example:
161
+
162
+ # config/application.rb
163
+ config.exception_handler = { dev: true }
164
+
165
+ # config/environments/production.rb
166
+ config.exception_handler = { social: { fusion: "flutils" }}
114
167
 
115
168
  ----
116
169
 
117
- **`ExceptionHandler 0.7.0`** has *drastically* improved our famous 1-click install.
170
+ ## Dev Mode
118
171
 
119
- Not only have we removed all the bloat, but our initialization process now relies on a *single* hook which will set all the config variables as required. This is stark difference to the myriad of poorly-designed gems which cause massive lag in your Rails initialization process. `ExceptionHandler` is now more streamlined than ever:
172
+ **To enable `ExceptionHandler` in dev, enable the [`dev`](lib/exception_handler/config.rb#L38) option:**
120
173
 
121
- <p align="center">
122
- <img src="readme/defaults.jpg" title="ExceptionHandler Default Config Options">
123
- </p>
174
+ # config/application.rb
175
+ config.exception_handler = { dev: true }
124
176
 
125
- The **MAGIC** lies in the [`environment files`](http://guides.rubyonrails.org/configuring.html#creating-rails-environments).
177
+ ![Dev][dev_mode]
126
178
 
127
- Instead of dopey initializers (which slow the system down), you can just use the Rails config files to set environment-dependent options. This allows us to maximize performance without any of the overhead associated with old-fashioned gems.
179
+ This disables [`config.consider_all_requests_local`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration), making Rails behave as it would in production:
128
180
 
129
- > **IMPORTANT**
130
- >
131
- > If you're upgrading from >= `0.4.7`, you need to **remove your `exception_handler` initializer**.
132
- >
133
- > We've changed the load process to use Rails app config - **you don't need the `exception_handler` initializer any more**
181
+ ![Dev][dev_img]
182
+
183
+ This should be used temporarily.
134
184
 
135
185
  ----
136
186
 
137
- <p id="defaults">
138
- <img src="readme/titles/setup/defaults.jpg" title="Defaults" height="75" border="2" />
139
- </p>
187
+ ## Database
140
188
 
141
- As can be seen in[`config`](/lib/exception_handler/config.rb), the following are all the options `ExceptionHandler` accepts:
189
+ **We also have `ActiveRecord` integration.**
142
190
 
143
- <p align="center">
144
- <img src="readme/defaults.jpg" title="ExceptionHandler Default Configuration Options">
145
- </p>
191
+ If you want to save your exceptions to `db`, you need to enable the `db` config option:
146
192
 
147
- # Defaults
148
- DEFAULTS = {
149
- dev: false, #-> defaults to "false" for dev mode
150
- db: false, #-> defaults to :errors if true, else use "table_name" / :table_name
151
- email: false, #-> requires string email and ActionMailer
152
- social: {
153
- facebook: { name: "frontline.utilities", url: "https://facebook.com" },
154
- twitter: { name: "frontlineutils", url: "http://twitter.com" },
155
- youtube: { name: "frontlineutils", url: "https://youtube.com/user" },
156
- linkedin: { name: "frontline-utilities", url: "https://linkedin.com/company" },
157
- fusion: { name: "flutils", url: "https://frontlinefusion.com" }
158
- },
159
- layouts: {
160
- "400" => nil, # => inherits from "ApplicationController" layout
161
- "500" => "exception"
162
- },
193
+ # config/application.rb
194
+ config.exception_handler = {
195
+ db: true
163
196
  }
164
197
 
165
- You can apply any of the above defaults into one of the Rails [`environment files`](http://guides.rubyonrails.org/configuring.html#creating-rails-environments):
198
+ This enables `ActiveRecord::Base` on the [`Exception`](app/models/exception_handler/exception.rb) class, allowing us to save to the database.
166
199
 
167
- - `config/application.rb`
168
- - `config/environments/development.rb`
169
- - `config/environments/production.rb`
170
- - `config/environments/staging.rb`
200
+ In order for this to work, your db needs the correct table.
171
201
 
172
- The benefit of this is that it gives you the ability to customize `ExceptionHandler` for *any* of your environments. Contrary to a shitty `initializer`, you're able to sculpt the gem to work for YOU.
202
+ To do this, once you've enabled the option, run `rails db:migrate` from your console. Our new [`migration system`](https://github.com/richpeck/exception_handler/tree/readme#migrations) will automatically run the migration.
173
203
 
174
- ----
204
+ ---
205
+
206
+ ## Email
175
207
 
176
- ![Development Mode][dev]
208
+ **`ExceptionHandler` also now sends email notifications.**
177
209
 
178
- Want to test in the `dev` environment?
210
+ If you want to receive emails whenever your application raises an error, you can do so by adding your email to the config:
179
211
 
180
212
  # config/application.rb
181
213
  config.exception_handler = {
182
- dev: true # -> Runs in development mode WITHOUT changing the app environment files
214
+ email: "your@email.com"
183
215
  }
184
216
 
185
- <img src="readme/dev.jpg" title="ExceptionHandler Dev Mode - NEW!!!!!">
217
+ > **Please Note** this requires [`ActionMailer`](http://guides.rubyonrails.org/action_mailer_basics.html). If you don't have any outbound SMTP server, [`SendGrid`](http://sendgrid.com) is free.
186
218
 
187
- [`config.exceptions_app`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration) *only* works when you have [`config.consider_all_requests_local = true`](http://blog.bigbinary.com/2009/02/05/rescue_action_in_public-local_request-and-how-to-configure-local_request.html), which is `true` in `development`:
219
+ [Full tutorial here](https://github.com/richpeck/exception_handler/wiki/2-Email)
188
220
 
189
- > **`config.consider_all_requests_local`** is a flag. If true then any error will cause detailed debugging information to be dumped in the `HTTP` response, and the `Rails::Info controller` will show the application runtime context in `/rails/info/properties`. `True` by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement `local_request?` in controllers to specify which requests should provide debugging information on errors.
221
+ ---
190
222
 
223
+ ## Views
191
224
 
192
- If you wish to test **`ExceptionHandler`** in `development`, you'll have to use the `dev: true` option in your `exception_handler` config, *or* change `config.consider_all_requests_local = true` in `config/development.rb`.
225
+ **From [`0.7.0`](#070), we overhauled the view system:**
193
226
 
194
- ----
227
+ ![View][view_img]
195
228
 
196
- <br />
197
- <img src="readme/titles/layout.jpg" title="Layout" id="layout" />
229
+ [Wiew](app/views/exception_handler/exceptions/show.html.erb) is modular - `@exception` populated with [`locales`](#locales).
198
230
 
199
- One of the most critial aspects of **`ExceptionHandler`** is the custom `Exception` layout.
231
+ ---
200
232
 
201
- If you want to change the layout (for `500` error pages), you need to use the following:
233
+ ## Locales
202
234
 
203
- <img src="readme/layout.jpg" title="Custom Exceptions Layout For ExceptionHandler" />
235
+ **[`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5) introduced [locales](config/locales/exception_handler.yml) ...**
204
236
 
205
- You'll need to [generate](#user-content-view) it into your application before being able to edit:
237
+ [[ locales ]]
206
238
 
207
- ----
239
+ The `ExceptionHandler` view is populated by [`@exception.description`](app/models/exception_handler/exception.rb#L121), which pulls from the `locales`.
208
240
 
209
- ![View][view]
241
+ If you want custom messages, you need the following. The key is defined by the HTTP [`status_code`](https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L544)
210
242
 
211
- **`ExceptionHandler`** comes with its own inbuilt views & controller.
243
+ # config/locales/en.yml
244
+ en:
245
+ exception_handler:
246
+ not_found: "Your message here"
247
+ unauthorized: "You need to login to continue"
248
+ internal_server_error: "This is a test to show the %{status} of the error"
212
249
 
213
- If you want to change it, you need to add the views into your app with the [`generator`](/lib/generators/exception_handler/views_generator.rb)
250
+ You get access to `%{message}` and `%{status}`, both inferring from `@exception`.
214
251
 
215
- $ rails generate exception_handler:views #-> controller, models, helpers, views & assets
216
- $ rails generate exception_handler:views -v views controllers models helpers assets #-> remove as appropriate to install individual assets
252
+ ---
217
253
 
218
- --
254
+ ## Layout
219
255
 
220
- <img src="readme/show.jpg" title="ExceptionHandler Show view" />
256
+ **The `layout` has also been improved ↴**
221
257
 
222
- `ExceptionHandler` uses `exceptions#show` -- located in **`app/views/exception_handler/show.html.erb`** designed to work for all exceptions.
258
+ ![Layout][layout_img]
223
259
 
224
- By default, it is split for use with different layouts, data being available to both.
260
+ We now assign layouts to the **status code** of the response:
225
261
 
226
- This works exactly the same as the other views in your app (IE the `exceptions controller` invokes the `show` action)
262
+ ![Layout][layouts_img]
227
263
 
228
- ----
264
+ By default, `5xx` errors are shown with our [`exception` layout][layout] - this can be overridden by changing the `config` to use a layout of your choice. If you want to inherit the `ApplicationController` layout, assign the codes to `nil`.
229
265
 
230
- ![Database][db]
266
+ ---
231
267
 
232
- If you want to store exceptions in your `db`, you will need to set up a **migration**:
233
268
 
234
- $ rails generate exception_handler:migration
235
- $ rake db:migrate
269
+ ## Custom Exceptions
236
270
 
237
- You will also need to ensure your config db option is either `true` or `"table_name"`:
271
+ **Custom Exceptions also supported in [`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)**
238
272
 
239
- <img src="readme/db.jpg" title="ExceptionHandler DB Config">
273
+ Rails handles this for us - [**`config.action_dispatch.rescue_responses`**][rescue_responses] ↴
240
274
 
241
- <img src="readme/db_screenshot.jpg" title="ExceptionHandler Database">
275
+ ![ActionDispatch][config.action_dispatch.rescue_responses]
242
276
 
243
- > **IMPORTANT**
244
- >
245
- > `ExceptionHandler`'s [new config system](https://github.com/richpeck/exception_handler/wiki/Setup) is `environment` agnostic.
246
- >
247
- > **Where you declare your `db` setting will change depending on your environment**
248
- >
249
- > If you declare `db` in `application.rb`, it will be applicable for all `environments`; only declaring in `production.rb` will set it for production *only*.
277
+ You need to add to the `rescue_responses` hash in your app's config (mapped to [`status codes`](https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L544)):
250
278
 
251
- ----
279
+ # config/application.rb
280
+ config.action_dispatch.rescue_responses["ActionController::YourError"] = :bad_request
281
+
282
+ Because `HTTP` can only process `4xx` / `5xx` errors, if `Rails` raises an exception, it needs to assign one of the error status codes. **Default** is [`internal_server_error`](https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L595) - if you'd prefer your app to just return `500` errors for your custom exception, you don't need to explicitly declare them.
283
+
284
+ ---
285
+
286
+ ## Generators
287
+
288
+ **You can generate `ExceptionHandler` into your own application.**
289
+
290
+ [[ Generator ]]
291
+
292
+ The following commands will copy the directories...
293
+
294
+ rails g exception_handler:views
295
+ rails g exception_handler:views -v views
296
+ rails g exception_handler:views -v controllers
297
+ rails g exception_handler:views -v models
298
+ rails g exception_handler:views -v assets
299
+ rails g exception_handler:views -v views controllers models assets
300
+
301
+ If you don't include any switches, this will copy **all** the folders put into your app.
252
302
 
253
- ### ![Support][support]
303
+ Each switch defines which folders you want (EG `-v views` will only copy `views` dir).
254
304
 
255
- We offer support through [GitHub](http://github.com/richpeck/exception_handler/issues) and [StackOverflow](http://stackoverflow.com/questions/ask?tags=ruby-on-rails+exception-handler).
305
+ ---
306
+
307
+ ### Migrations (deprecated)
308
+
309
+ **From [`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5), the `migration` generator has been removed in favour of our own [migration system](lib/exception_handler/engine.rb#L58)**
256
310
 
257
- Whilst we can't guarantee response times, we are always eager to make sure `ExceptionHandler` is the most secure, robust and effective solution for Rails exception pages. You can use the links below to access support directly:
311
+ You don't need to generate a migration any more.
258
312
 
259
- Github (~1hr) | Stackoverflow (~24hrs)
260
- :----: | :----:
261
- [![StackOverflow](readme/github.jpg)](https://github.com/richpeck/exception_handler/issues) | [![StackOverflow](readme/stackoverflow.jpg)](http://stackoverflow.com/questions/ask?tags=ruby-on-rails+exception-handler)
313
+ If you set the `db` option in config, run `rails db:migrate` and the migration will be run.
262
314
 
263
- We use **`ExceptionHandler`** in production, so have a vested interest in keeping it running smoothly.
315
+ To rollback, use the following:
316
+
317
+ rails db:migrate:down VERSION=000000
318
+
319
+ > The drawback to this is that if you remove `ExceptionHandler` before you rollback the migration, it won't exist anymore. You can **only** fire the `rollback` when you have `ExceptionHandler` installed.
264
320
 
265
321
  ---
266
322
 
267
- # ![Changelog - Current Version 0.7.0][changelog]
323
+ ## Support
268
324
 
269
- Current version is [**`0.7.0`**](https://github.com/richpeck/exception_handler/releases/latest)
325
+ [Issues](https://github.com/richpeck/exception_handler/issues)
270
326
 
271
- Functionality remains consistent with previous releases, main difference will be the way in which they handle backend processes. **`0.7.0`** completely overhauled the backend, making the `controller`, `model` and `middleware` much more streamlined.
327
+ ---
272
328
 
273
- The biggest update for **`0.7.0.`** has been the removal of most middleware, putting the entire system into a central class. This not only allows us to centralize the data structure, but also remove many files which didn't matter.
329
+ ## Changelog
274
330
 
275
- Here is a rundown of what's been implemented ↴
331
+ ### [0.7.5](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)
332
+ - [x] [HTTP status layouts](#layouts)
276
333
 
277
- ### [0.7.0](https://github.com/richpeck/exception_handler/releases/tag/0.7.0)
278
- - [ ] Wildcard mime types
279
- - [ ] Custom exceptions
334
+ ### [0.7.0](https://github.com/richpeck/exception_handler/releases/tag/0.7.0)
335
+ - [x] Wildcard mime types
336
+ - [x] [Custom exceptions](#custom_exceptions)
280
337
  - [x] Test suite integration
281
- - [ ] Exception "mapping" (choose which exceptions to handle)
282
- - [x] [Email](https://github.com/richpeck/exception_handler/wiki/2-Email)
283
- - [x] Model backend
338
+ - [x] [Email](#email)
339
+ - [x] [Model backend](#database)
284
340
  - [x] Sprockets 4+
341
+ - [x] New layout
285
342
  - [x] Readme / wiki overhaul
286
343
 
287
- ### [0.6.5](https://github.com/richpeck/exception_handler/releases/tag/0.6.5)
344
+ ### [0.6.5](https://github.com/richpeck/exception_handler/releases/tag/0.6.5)
288
345
  - [x] Streamlined interface
289
346
  - [x] ActiveRecord / Middleware overhaul
290
347
  - [x] Supports Sprockets 4+ ([`manifest.js`](http://eileencodes.com/posts/the-sprockets-4-manifest/))
@@ -292,8 +349,8 @@ Here is a rundown of what's been implemented ↴
292
349
  - [x] Asset overhaul & improvement
293
350
  - [x] Removed dependencies
294
351
 
295
- ### [0.5.0](https://github.com/richpeck/exception_handler/releases/tag/0.5.0)
296
- - [x] Added locales
352
+ ### [0.5.0](https://github.com/richpeck/exception_handler/releases/tag/0.5.0)
353
+ - [x] Locales
297
354
  - [x] Email notifications
298
355
  - [x] Full test suite
299
356
  - [x] Rails 4.2 & Rails 5.0 native ([`request.env`](https://github.com/rails/rails/commit/05934d24aff62d66fc62621aa38dae6456e276be) fix)
@@ -301,13 +358,36 @@ Here is a rundown of what's been implemented ↴
301
358
  - [x] `DB` fixed
302
359
  - [x] Legacy initializer support ([more](https://github.com/richpeck/exception_handler/wiki/1-Setup))
303
360
  - [x] Rails asset management improvement
304
- - [x] Reduced gem file
361
+ - [x] Reduced gem file size
305
362
 
306
- ### [0.4.6](https://github.com/richpeck/exception_handler/releases/tag/0.4.6)
307
- - [x] New config system ([more](https://github.com/richpeck/exception_handler/wiki/1-Setup))
363
+ ### [0.4.7](https://github.com/richpeck/exception_handler/releases/tag/0.4.6)
364
+ - [x] New config system
308
365
  - [x] Fixed controller layout issues
309
366
  - [x] Streamlined middleware
310
- - [x] New layout & interface implementation
367
+ - [x] New layout & interface
368
+
369
+ ----
370
+
371
+ [![404 + 500 Errors][banner]][rubygems]
372
+
373
+ <p align="center">
374
+ <strong><a href="#">ExceptionHandler</a> is now the leading custom error pages gem for Rails.</strong>
375
+ <br />
376
+ No other gem is as simple or effective at providing beautiful exception pages in production.
377
+ </p>
378
+
379
+ <p align="center">
380
+ <a href="http://badge.fury.io/rb/exception_handler"><img src="https://badge.fury.io/rb/exception_handler.svg" align="absmiddle"></a>
381
+ <a href="http://rubygems.org/gems/exception_handler"><img src="http://ruby-gem-downloads-badge.herokuapp.com/exception_handler/0.5.1?type=total&color=brightgreen" align="absmiddle" /></a>
382
+ <a href="https://codeclimate.com/github/richpeck/exception_handler"><img src="https://codeclimate.com/github/richpeck/exception_handler/badges/gpa.svg" align="absmiddle"/></a>
383
+ <a href="https://gemnasium.com/richpeck/exception_handler"><img src="https://gemnasium.com/richpeck/exception_handler.svg" align="absmiddle"></a>
384
+ <a href='https://coveralls.io/github/richpeck/exception_handler?branch=master'><img src='https://coveralls.io/repos/github/richpeck/exception_handler/badge.svg?branch=master' alt='Coverage Status' align="absmiddle" /></a>
385
+ <a href="https://travis-ci.org/richpeck/exception_handler"><img src="https://travis-ci.org/richpeck/exception_handler.svg?branch=master" align="absmiddle"></a>
386
+ </p>
387
+
388
+ <p align="center">
389
+ <strong><a href="https://rubygems.org/gems/exception_handler">Download Here</a></strong>
390
+ </p>
311
391
 
312
392
  ----------
313
393
 
@@ -321,7 +401,15 @@ Here is a rundown of what's been implemented ↴
321
401
  <!-- Images https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#images -->
322
402
 
323
403
  <!-- Images -->
324
- [config.exceptions_app]: readme/config.exceptions_app.jpg
404
+ [dev_mode]: readme/dev_mode.jpg
405
+ [dev_img]: readme/dev.png
406
+ [layouts_img]: readme/layouts.jpg
407
+ [layout_img]: readme/layout.png
408
+ [view_img]: readme/view.jpg
409
+ [http_codes]: readme/http_codes.png
410
+ [config]: readme/config.jpg
411
+ [config.action_dispatch.rescue_responses]: readme/config.action_dispatch.rescue_responses.jpg
412
+ [banner]: readme/banner.jpg
325
413
  [gem]: readme/gem.jpg
326
414
  [gemfile]: readme/gemfile.jpg
327
415
  [middleware]: readme/middleware.jpg
@@ -336,14 +424,20 @@ Here is a rundown of what's been implemented ↴
336
424
  [profile]: https://avatars0.githubusercontent.com/u/1104431 "R Peck"
337
425
 
338
426
  <!-- Links -->
339
- [latest]: https://github.com/richpeck/exception_handler/releases/latest
427
+ [better_errors]: https://github.com/charliesome/better_errors
428
+ [layout]: app/views/layouts/exception.html.erb
429
+ [status_codes]: http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
430
+ [stackoverflow]: http://stackoverflow.com/questions/ask?tags=ruby-on-rails+exception-handler
431
+ [rescue_responses]: http://guides.rubyonrails.org/configuring.html#configuring-action-dispatch
432
+ [latest]: https://github.com/richpeck/exception_handler/releases/latest
340
433
  [show_exception]: https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
341
- [exception_app]: http://guides.rubyonrails.org/configuring.html#rails-general-configuration
342
- [rubygems]: http://rubygems.org/gems/exception_handler
434
+ [exception_app]: http://guides.rubyonrails.org/configuring.html#rails-general-configuration
435
+ [rubygems]: http://rubygems.org/gems/exception_handler
343
436
  [frontlineutilities.co.uk]: http://www.frontlineutilities.co.uk
344
- [stackoverflow.com]: http://stackoverflow.com/users/1143732/richard-peck?tab=profile
345
- [fork]: #fork-destination-box
346
- [pull]: http://github.com/richpeck/exception_handler/pulls
437
+ [stackoverflow.com]: http://stackoverflow.com/users/1143732/richard-peck?tab=profile
438
+ [fork]: #fork-destination-box
439
+ [pull]: http://github.com/richpeck/exception_handler/pulls
440
+ [issues]: http://github.com/richpeck/exception_handler/issues
347
441
 
348
442
  <!-- ################################### -->
349
443
  <!-- ################################### -->
@@ -47,7 +47,7 @@
47
47
  line-height: 11px;
48
48
  color: rgba(255,255,255,1);
49
49
  text-align: center;
50
- box-siing: border-box;
50
+ box-sizing: border-box;
51
51
 
52
52
  border-width: 0 1px 1px;
53
53
  border-color: rgba(255,255,255,0.09);
@@ -1,5 +1,5 @@
1
1
  module ExceptionHandler
2
- class ExceptionController < ApplicationController
2
+ class ExceptionsController < ApplicationController
3
3
 
4
4
  # => Response
5
5
  # => http://www.justinweiss.com/articles/respond-to-without-all-the-pain/
@@ -28,7 +28,7 @@ module ExceptionHandler
28
28
  # => Layout
29
29
  # => Layouts only 400 / 500 because they are the only error responses (300 is redirect)
30
30
  # => http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
31
- # => Layout proc kills inheritance, needs to be method for now
31
+ # => Layout proc kills "nil" inheritance, needs to be method for now
32
32
  layout :layout
33
33
 
34
34
  ####################
@@ -45,8 +45,11 @@ module ExceptionHandler
45
45
  private
46
46
 
47
47
  def layout
48
- ExceptionHandler.config.layouts[ @exception.status[0] + "00" ]
48
+ ExceptionHandler.config.layouts[@exception.status]
49
49
  end
50
50
 
51
+ ##################################
52
+ ##################################
53
+
51
54
  end
52
55
  end
@@ -89,7 +89,7 @@ module ExceptionHandler
89
89
  # => Email
90
90
  # => after_initialize invoked after .new method called
91
91
  # => Should have been after_create but user may not save
92
- after_initialize Proc.new { |e| ExceptionHandler::ExceptionMailer.new_exception(e).deliver } if ExceptionHandler.config.try(:email) && ExceptionHandler.config.email.is_a?(String)
92
+ after_initialize Proc.new { |e| ExceptionHandler::ExceptionMailer.new_exception(e).deliver } if ExceptionHandler.config.try(:email).try(:is_a?, String)
93
93
 
94
94
  # => Attributes
95
95
  attr_accessor :request, :klass, :exception, :description
@@ -119,8 +119,8 @@ module ExceptionHandler
119
119
 
120
120
  # => Description
121
121
  def description
122
- I18n.with_options scope: [:exception], message: message, status: status do |i18n|
123
- i18n.t response, default: status
122
+ I18n.with_options scope: [:exception_handler], message: message, status: status do |i18n|
123
+ i18n.t response, default: Rack::Utils::HTTP_STATUS_CODES[status] || status
124
124
  end
125
125
  end
126
126
 
@@ -173,7 +173,7 @@ module ExceptionHandler
173
173
 
174
174
  # => Status code (404, 500 etc)
175
175
  def status
176
- ActionDispatch::ExceptionWrapper.new(request.env, exception).status_code.to_s
176
+ ActionDispatch::ExceptionWrapper.new(request.env, exception).status_code
177
177
  end
178
178
 
179
179
  # => Server Response ("Not Found" etc)
@@ -1,13 +1,29 @@
1
- ##################################
2
- ##################################
1
+ #######################################################################################
2
+ #######################################################################################
3
+ ## _____ _ _ _ _ _ _ ##
4
+ ## | ___| | | (_) | | | | | | | ##
5
+ ## | |____ _____ ___ _ __ | |_ _ ___ _ __ | |_| | __ _ _ __ __| | | ___ _ __ ##
6
+ ## | __\ \/ / __/ _ \ '_ \| __| |/ _ \| '_ \ | _ |/ _` | '_ \ / _` | |/ _ \ '__| ##
7
+ ## | |___> < (_| __/ |_) | |_| | (_) | | | | | | | | (_| | | | | (_| | | __/ | ##
8
+ ## \____/_/\_\___\___| .__/ \__|_|\___/|_| |_| \_| |_/\__,_|_| |_|\__,_|_|\___|_| ##
9
+ ## | | ##
10
+ ## |_| ##
11
+ #######################################################################################
12
+ #######################################################################################
13
+
3
14
  # Have to use strings rather than integers
4
- ##################################
5
- ##################################
15
+ # https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L544
16
+
17
+ # By default, exceptions will show their "response" code (404 = "Not Found")
18
+ # If you want to create custom messages, you have to assign the values as [response]: "message"
19
+
20
+ #######################################################################################
21
+ #######################################################################################
6
22
 
7
23
  en:
8
- exception:
24
+ exception_handler:
9
25
  not_found: "Page missing"
10
26
  internal_server_error: "<strong>%{status} Error</strong> %{message} <p>Return home</p>"
11
27
 
12
- ##################################
13
- ##################################
28
+ #######################################################################################
29
+ #######################################################################################
@@ -0,0 +1,34 @@
1
+ class CreateErrors < ActiveRecord::Migration[5.0]
2
+
3
+ # => ATTRS
4
+ require_relative "../../app/models/exception_handler/exception.rb"
5
+
6
+ #########################################
7
+ #########################################
8
+
9
+ # => Defs
10
+ @@table = ExceptionHandler.config.try(:db)
11
+
12
+ #########################################
13
+
14
+ # Up
15
+ def up
16
+ create_table @@table do |t|
17
+ ExceptionHandler::ATTRS.each do |attr|
18
+ t.text attr
19
+ end
20
+ t.timestamps
21
+ end
22
+ end
23
+
24
+ #########################################
25
+
26
+ # Down
27
+ def down
28
+ drop_table @@table, if_exists: true
29
+ end
30
+
31
+ #########################################
32
+ #########################################
33
+
34
+ end
@@ -11,7 +11,7 @@ module ExceptionHandler
11
11
  module VERSION
12
12
  MAJOR = 0
13
13
  MINOR = 7
14
- TINY = 0
14
+ TINY = 5
15
15
  PRE = nil # "alpha"
16
16
 
17
17
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -3,16 +3,29 @@
3
3
 
4
4
  module ExceptionHandler
5
5
 
6
- # => Table Prefix
7
- # => Keeps Rails Engine from generating all table prefixes with the engines name
8
- # => http://stackoverflow.com/questions/19435214/rails-mountable-engine-with-isolate-namespace-but-without-prefixed-namespace-on
9
- def self.table_name_prefix
10
- # => No prefix
11
- end
12
-
13
- # => Config
14
- # => Invoke instance of config (ExceptionHandler.config)
15
- mattr_accessor :config
6
+ ##############################
7
+ ##############################
8
+
9
+ # => Table Prefix
10
+ # => Keeps Rails Engine from generating all table prefixes with the engines name
11
+ # => http://stackoverflow.com/questions/19435214/rails-mountable-engine-with-isolate-namespace-but-without-prefixed-namespace-on
12
+ def self.table_name_prefix
13
+ # => No prefix
14
+ end
15
+
16
+ # => Config
17
+ # => Invoke instance of config (ExceptionHandler.config)
18
+ mattr_accessor :config
19
+
20
+ ##############################
21
+ ##############################
22
+
23
+ # => Exceptions
24
+ # => https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/errors.rb
25
+ class Error < StandardError; end
26
+
27
+ ##############################
28
+ ##############################
16
29
 
17
30
  end
18
31
 
@@ -9,72 +9,95 @@
9
9
  module ExceptionHandler
10
10
  class Config
11
11
 
12
- #Instace Objects
13
- attr_accessor :dev, :db, :email, :social, :layouts
12
+ # => Instace Objects
13
+ # => ExceptionHandler.config.dev
14
+ # => ExceptionHandler.config.db
15
+ # => ExceptionHandler.config.email
16
+ # => ExceptionHandler.config.social
17
+ # => ExceptionHandler.config.layouts
18
+ # => ExceptionHandler.config.custom_exceptions
19
+ attr_accessor :dev, :db, :email, :social, :layouts, :custom_exceptions
14
20
 
21
+ ###########################################
22
+ ###########################################
15
23
  ###########################################
16
24
  ###########################################
17
25
 
18
- # Table Name
19
- # Has to be "errors" because "exceptions" is a reserved word
20
- TABLE = :errors
26
+ # => Table Name
27
+ # => Has to be "errors" because "exceptions" is a reserved word
28
+ TABLE = :errors
21
29
 
22
- # Social URLs
23
- # Extracted from "social" block
24
- SOCIAL = {
25
- facebook: "https://facebook.com",
26
- twitter: "http://twitter.com",
27
- youtube: "https://youtube.com/user",
28
- linkedin: "https://linkedin.com/company",
29
- fusion: "http://frontlinefusion.com"
30
- }
30
+ # => Social URLs
31
+ # => Extracted from "social" block
32
+ SOCIAL = {
33
+ facebook: "https://facebook.com",
34
+ twitter: "https://twitter.com",
35
+ youtube: "https://youtube.com/user",
36
+ linkedin: "https://linkedin.com/company",
37
+ fusion: "https://frontlinefusion.com"
38
+ }
31
39
 
32
40
  ###########################################
33
41
  ###########################################
34
42
 
35
- # Defaults
36
- # http://stackoverflow.com/a/8917301/1143732
37
- DEFAULTS = {
38
- dev: false, #-> defaults to "false" for dev mode
39
- db: false, #-> defaults to :errors if true, else use "table_name" / :table_name
40
- email: false, #-> requires string email and ActionMailer
41
- social: {
42
- facebook: nil,
43
- twitter: nil,
44
- youtube: nil,
45
- linkedin: nil,
46
- fusion: nil,
47
- },
48
- layouts: {
49
- "400" => nil, # => inherits from "ApplicationController" layout
50
- "500" => "exception"
51
- },
52
- }
43
+ # => Defaults
44
+ # => http://stackoverflow.com/a/8917301/1143732
45
+ DEFAULTS = {
46
+ dev: nil, # => defaults to "false" for dev mode
47
+ db: nil, # => defaults to :errors if true, else use "table_name" / :table_name
48
+ email: nil, # => requires string email and ActionMailer
49
+ social: {
50
+ facebook: nil,
51
+ twitter: nil,
52
+ youtube: nil,
53
+ linkedin: nil,
54
+ fusion: nil,
55
+ },
56
+ layouts: {
57
+ # => nil inherits from ApplicationController
58
+ # => 4xx errors should be nil
59
+ # => 5xx errors should be "exception" but can be nil if explicitly defined
60
+ 500 => "exception",
61
+ 501 => "exception",
62
+ 502 => "exception",
63
+ 503 => "exception",
64
+ 504 => "exception",
65
+ 505 => "exception",
66
+ 507 => "exception",
67
+ 510 => "exception"
68
+ }
69
+ }
53
70
 
54
71
  ###########################################
55
72
  ###########################################
56
73
 
57
- #Init
74
+ # => Init
75
+ # => Merges DEFAULTS to values, creates instances vars (for attr_accessor)
58
76
  def initialize values
77
+
59
78
  # => Vars
60
79
  DEFAULTS.deep_merge!(values || {}).each do |k,v|
61
80
  instance_variable_set("@#{k}",v)
62
81
  end
63
82
 
64
- # => Errors
65
- raise(Exception, "ExceptionHandler :: Valid Email Required") if @email && !@email.is_a?(String)
66
- #raise(Exception, "ExceptionHandler :: Migration Required → Table \"#{db}\" doesn't exist") if @db && !ActiveRecord::Base.connection.table_exists?(db)
83
+ # => Validation
84
+ raise ExceptionHandler::Error, "Email Not Valid" if @email && !@email.nil? && !@email.is_a?(String)
85
+ raise ExceptionHandler::Error, "Migration Required → \"#{db}\" doesn't exist" if @db && !ActiveRecord::Base.connection.table_exists?(db)
67
86
  end
68
87
 
69
88
  ###########################################
70
89
  ###########################################
71
90
 
91
+ # => DB
92
+ # => If config db = "true", use TABLE constant
72
93
  def db
73
- @db == true ? TABLE : @db
94
+ @db == true ? TABLE : @db.try(:parameterize, separator: "_")
74
95
  end
75
96
 
76
97
  ###########################################
77
98
  ###########################################
99
+ ###########################################
100
+ ###########################################
78
101
 
79
102
  end
80
103
  end
@@ -4,6 +4,8 @@ module ExceptionHandler
4
4
  # => Rails default MIME types:
5
5
  # => http://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to#14-Rails-defined-Mime-Types
6
6
 
7
+ #########################################################
8
+ #########################################################
7
9
  #########################################################
8
10
  #########################################################
9
11
 
@@ -19,26 +21,40 @@ module ExceptionHandler
19
21
 
20
22
  # => Assets
21
23
  # => For Sprockets 4, had to include link_tree in exception_handler.css
22
- config.assets.precompile << %w(exception_handler.css)
24
+ config.assets.precompile << "exception_handler.css"
23
25
 
24
26
  #########################################################
25
27
  #########################################################
26
28
 
27
- # => Hooks
28
- # => This should be config.before_initialize but because ActiveRecord is not initialized, cannot check for table
29
- initializer :exception_handler, before: "better_errors.configure_rails_initialization" do |app|
30
-
31
- # => Vars
29
+ # => Config
30
+ # => Builds lib/exception_handler/config.rb
31
+ config.before_initialize do |app|
32
32
  ExceptionHandler.config ||= ExceptionHandler::Config.new config.try(:exception_handler)
33
+ end
34
+
35
+ #########################################################
36
+ #########################################################
33
37
 
34
- # => Middleware
35
- app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionController.action(:show).call(env) }
38
+ # => Middleware
39
+ # => This should be config.before_initialize but because ActiveRecord is not initialized, cannot check for table
40
+ initializer :exception_handler, before: "better_errors.configure_rails_initialization" do |app|
41
+ app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionsController.action(:show).call(env) }
36
42
  app.config.consider_all_requests_local = !ExceptionHandler.config.try(:dev) if Rails.env.development?
43
+ end
37
44
 
45
+ # => Migrations
46
+ # => This has to be kept in an initializer (to access app)
47
+ # => https://blog.pivotal.io/labs/labs/leave-your-migrations-in-your-rails-engines
48
+ initializer :migration_paths do |app|
49
+ config.paths["db/migrate"].expanded.each do |expanded_path|
50
+ app.config.paths["db/migrate"] << expanded_path if ExceptionHandler.config.try(:db)
51
+ end
38
52
  end
39
53
 
40
54
  #########################################################
41
55
  #########################################################
56
+ #########################################################
57
+ #########################################################
42
58
 
43
59
  end
44
60
  end
@@ -1,42 +1,33 @@
1
1
  module ExceptionHandler
2
2
  class ViewsGenerator < Rails::Generators::Base
3
3
 
4
- #Views
5
- VIEWS = %w(views controllers models assets)
6
-
7
- #Options
8
- class_option :files, aliases: "-v", default: VIEWS, type: :array, desc: "Select file types (views, models, controllers, assets)"
9
-
10
- #Needed to reference files
11
- source_root File.expand_path("../../../../app", __FILE__)
12
-
13
4
  ###########################################
14
-
15
- #Files
16
- def create_files
17
- generate_files options.files
18
- end
19
-
5
+ ###########################################
20
6
  ###########################################
21
7
 
22
- protected
8
+ #Views
9
+ VIEWS = %w(views controllers models assets)
23
10
 
24
- #File Generator
25
- def generate_files args
11
+ #Options
12
+ class_option :files, aliases: "-v", default: VIEWS, type: :array, desc: "Select file types (views, models, controllers, assets)"
26
13
 
27
- #Valid?
28
- return raise args.inspect unless args.nil? || (args-VIEWS).empty?
14
+ #Needed to reference files
15
+ source_root File.expand_path("../../../../app", __FILE__)
29
16
 
30
- #Types
31
- for arg in args do
32
- directory arg, "app/#{arg}"
33
- end
17
+ ###########################################
18
+ ###########################################
19
+ ###########################################
34
20
 
35
- #Success
36
- puts "Files transferred successfully"
37
- end
21
+ #Files
22
+ def create_files
23
+ options.files.each do |arg|
24
+ directory arg, "app/#{arg}"
25
+ end
26
+ end
38
27
 
39
28
  ###########################################
29
+ ###########################################
30
+ ###########################################
40
31
 
41
32
  end
42
33
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
  #####################################
5
5
 
6
6
  # => ExceptionController
7
- describe ExceptionHandler::ExceptionController do
7
+ describe ExceptionHandler::ExceptionsController do
8
8
 
9
9
 
10
10
  # => @exception
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Peck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-05 00:00:00.000000000 Z
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,6 +130,7 @@ executables: []
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
+ - ".gitattributes"
133
134
  - ".gitignore"
134
135
  - ".rspec"
135
136
  - ".travis.yml"
@@ -137,7 +138,6 @@ files:
137
138
  - LICENSE.txt
138
139
  - README.md
139
140
  - Rakefile
140
- - app/assets/images/exception_handler.ico
141
141
  - app/assets/images/exception_handler/alert.jpg
142
142
  - app/assets/images/exception_handler/alert.png
143
143
  - app/assets/images/exception_handler/bg.jpg
@@ -156,22 +156,21 @@ files:
156
156
  - app/assets/stylesheets/styles/_exception.css.erb
157
157
  - app/assets/stylesheets/styles/_footer.css.erb
158
158
  - app/assets/stylesheets/styles/_responsive.css
159
- - app/controllers/exception_handler/exception_controller.rb
159
+ - app/controllers/exception_handler/exceptions_controller.rb
160
160
  - app/mailers/exception_handler/exception_mailer.rb
161
161
  - app/models/exception_handler/exception.rb
162
- - app/views/exception_handler/exception/show.html.erb
162
+ - app/views/exception_handler/exceptions/show.html.erb
163
163
  - app/views/exception_handler/mailers/layout.haml
164
164
  - app/views/exception_handler/mailers/layout.text.erb
165
165
  - app/views/exception_handler/mailers/new_exception.erb
166
166
  - app/views/layouts/exception.html.erb
167
167
  - config/locales/exception_handler.en.yml
168
+ - db/migrate/000000_create_errors.rb
168
169
  - exception_handler.gemspec
169
170
  - lib/exception_handler.rb
170
171
  - lib/exception_handler/config.rb
171
172
  - lib/exception_handler/engine.rb
172
- - lib/generators/exception_handler/migration_generator.rb
173
173
  - lib/generators/exception_handler/views_generator.rb
174
- - lib/generators/templates/migration.rb.erb
175
174
  - spec/database.yml
176
175
  - spec/dummy/Rakefile
177
176
  - spec/dummy/app/assets/config/manifest.js
@@ -1,55 +0,0 @@
1
- ###########################################
2
-
3
- require 'rails/generators/active_record'
4
- require 'exception_handler/exception' # => ATTRS constant (for attributes)
5
-
6
- ###########################################
7
-
8
- # => Migration Generator (for adding errors table)
9
- # => Ref: https://github.com/plataformatec/devise/blob/master/lib/generators/active_record/devise_generator.rb
10
-
11
- module ExceptionHandler
12
- class MigrationGenerator < ActiveRecord::Generators::Base
13
-
14
- # => Name - from http://old.thoughtsincomputation.com/posts/cgfr3-part-3-adding-a-generator
15
- argument :name, default: "migration"
16
-
17
- # => Source of Migrations
18
- source_root File.expand_path("../../templates", __FILE__)
19
-
20
- ###########################################
21
-
22
- # => Table Name - false = off, true = errors, value = value
23
- # => Always outputs string for some reason...
24
- def table_name
25
- ExceptionHandler.config.db
26
- end
27
-
28
- ###########################################
29
-
30
- # => Create
31
- def create_errors_migration
32
- migration_template "migration.rb.erb", "db/migrate/create_#{table_name.to_s.gsub("_","")}.rb", migration_version: migration_version
33
- end
34
-
35
- ###########################################
36
-
37
- # => From Devise
38
- # => https://github.com/plataformatec/devise/blob/master/lib/generators/active_record/devise_generator.rb#L81
39
-
40
- # => Rails 5?
41
- def rails5?
42
- Rails.version.start_with? '5'
43
- end
44
-
45
- # => Migration Version
46
- def migration_version
47
- if rails5?
48
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
49
- end
50
- end
51
-
52
- ###########################################
53
-
54
- end
55
- end
@@ -1,16 +0,0 @@
1
- class Create<%= table_name.to_s.gsub("_","").titleize %> < ActiveRecord::Migration<%= migration_version %>
2
-
3
- def self.up
4
- create_table :<%= table_name %> do |t|
5
- <% ExceptionHandler::ATTRS.each do |attr| %>
6
- t.text :<%= attr %>
7
- <% end %>
8
- t.timestamps
9
- end
10
- end
11
-
12
- def self.down
13
- drop_table :<%= table_name %>
14
- end
15
-
16
- end