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 +4 -4
- data/.gitattributes +1 -0
- data/README.md +235 -141
- data/app/assets/stylesheets/styles/_exception.css.erb +1 -1
- data/app/controllers/exception_handler/{exception_controller.rb → exceptions_controller.rb} +6 -3
- data/app/models/exception_handler/exception.rb +4 -4
- data/app/views/exception_handler/{exception → exceptions}/show.html.erb +0 -0
- data/config/locales/exception_handler.en.yml +23 -7
- data/db/migrate/000000_create_errors.rb +34 -0
- data/exception_handler.gemspec +1 -1
- data/lib/exception_handler.rb +23 -10
- data/lib/exception_handler/config.rb +60 -37
- data/lib/exception_handler/engine.rb +24 -8
- data/lib/generators/exception_handler/views_generator.rb +18 -27
- data/spec/exception_handler/exception_controller_spec.rb +1 -1
- metadata +6 -7
- data/app/assets/images/exception_handler.ico +0 -0
- data/lib/generators/exception_handler/migration_generator.rb +0 -55
- data/lib/generators/templates/migration.rb.erb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccc92609ab7af5a0f65736e1578aaef57b51a2d7
|
4
|
+
data.tar.gz: 1843d7a57a2551baa486a8579e60594eca2e2d5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0af19ea19133e86ad15a43f9324ee923ebdce75a7747543bd57f799ca16c8b14f0f24b81ce6ed144c8a6cd78169c2aa5e0b6c8bc5780af801bf1d169acc57fb9
|
7
|
+
data.tar.gz: 0740300edaa518daf6db9e133b75650684bdcaf3b276b84c7e4568b9fd61d5032d8d0c14c5037ceaa72998c58076d059a7970b2a2d8321dbd95c526cb8e4fddd
|
data/.gitattributes
ADDED
@@ -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/
|
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="#
|
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/
|
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="
|
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" /> <strong align="absmiddle">Fully Rails 4 & 5 Compatible</strong>
|
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/
|
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
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
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
|
-
|
101
|
+
**`ExceptionHandler` is the most EFFECTIVE and EFFICIENT gem to handle exceptions in Rails**.
|
89
102
|
|
90
|
-
|
91
|
-
|
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/
|
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
|
-
|
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"
|
105
|
-
|
106
|
-
|
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> <a href="#dev-mode" title="Dev Mode"><img src="readme/titles/icons/dev.png" alt="Dev" align="absmiddle" height="24" /> Dev</a> <a href="#database"><img src="readme/titles/icons/database.png" alt="Database" align="absmiddle" height="24" /> Database</a> <a href="#email"><img src="readme/titles/icons/email.png" alt="Email" align="absmiddle" height="24" /> Email</a> <a href="#views"><img src="readme/titles/icons/views.png" alt="Views" align="absmiddle" height="24" /> Views</a> <a href="#locales"><img src="readme/titles/icons/locales.png" alt="Locales" align="absmiddle" height="24" /> Locales</a> <a href="#custom-exceptions"><img src="readme/titles/icons/custom.png" alt="Custom Exceptions" align="absmiddle" height="24" /> Custom Exceptions</a> <a href="#generators"><img src="readme/titles/icons/generators.png" alt="Generators" align="absmiddle" height="24" /> Generators</a>
|
107
134
|
</p>
|
108
135
|
|
109
|
-
|
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
|
-
|
144
|
+
If you're using an [`engine`](http://guides.rubyonrails.org/engines.html), you don't need to use an `initializer`:
|
112
145
|
|
113
|
-
|
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
|
-
|
170
|
+
## Dev Mode
|
118
171
|
|
119
|
-
|
172
|
+
**To enable `ExceptionHandler` in dev, enable the [`dev`](lib/exception_handler/config.rb#L38) option:**
|
120
173
|
|
121
|
-
|
122
|
-
|
123
|
-
</p>
|
174
|
+
# config/application.rb
|
175
|
+
config.exception_handler = { dev: true }
|
124
176
|
|
125
|
-
|
177
|
+
![Dev][dev_mode]
|
126
178
|
|
127
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
138
|
-
<img src="readme/titles/setup/defaults.jpg" title="Defaults" height="75" border="2" />
|
139
|
-
</p>
|
187
|
+
## Database
|
140
188
|
|
141
|
-
|
189
|
+
**We also have `ActiveRecord` integration.**
|
142
190
|
|
143
|
-
|
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
|
-
#
|
148
|
-
|
149
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
208
|
+
**`ExceptionHandler` also now sends email notifications.**
|
177
209
|
|
178
|
-
|
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
|
-
|
214
|
+
email: "your@email.com"
|
183
215
|
}
|
184
216
|
|
185
|
-
|
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
|
-
[
|
219
|
+
[Full tutorial here](https://github.com/richpeck/exception_handler/wiki/2-Email)
|
188
220
|
|
189
|
-
|
221
|
+
---
|
190
222
|
|
223
|
+
## Views
|
191
224
|
|
192
|
-
|
225
|
+
**From [`0.7.0`](#070), we overhauled the view system:**
|
193
226
|
|
194
|
-
|
227
|
+
![View][view_img]
|
195
228
|
|
196
|
-
|
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
|
-
|
231
|
+
---
|
200
232
|
|
201
|
-
|
233
|
+
## Locales
|
202
234
|
|
203
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
250
|
+
You get access to `%{message}` and `%{status}`, both inferring from `@exception`.
|
214
251
|
|
215
|
-
|
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
|
-
|
256
|
+
**The `layout` has also been improved ↴**
|
221
257
|
|
222
|
-
|
258
|
+
![Layout][layout_img]
|
223
259
|
|
224
|
-
|
260
|
+
We now assign layouts to the **status code** of the response:
|
225
261
|
|
226
|
-
|
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
|
-
|
266
|
+
---
|
231
267
|
|
232
|
-
If you want to store exceptions in your `db`, you will need to set up a **migration**:
|
233
268
|
|
234
|
-
|
235
|
-
$ rake db:migrate
|
269
|
+
## Custom Exceptions
|
236
270
|
|
237
|
-
|
271
|
+
**Custom Exceptions also supported in [`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)**
|
238
272
|
|
239
|
-
|
273
|
+
Rails handles this for us - [**`config.action_dispatch.rescue_responses`**][rescue_responses] ↴
|
240
274
|
|
241
|
-
|
275
|
+
![ActionDispatch][config.action_dispatch.rescue_responses]
|
242
276
|
|
243
|
-
|
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
|
-
|
303
|
+
Each switch defines which folders you want (EG `-v views` will only copy `views` dir).
|
254
304
|
|
255
|
-
|
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
|
-
|
311
|
+
You don't need to generate a migration any more.
|
258
312
|
|
259
|
-
|
260
|
-
:----: | :----:
|
261
|
-
[](https://github.com/richpeck/exception_handler/issues) | [](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
|
-
|
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
|
-
|
323
|
+
## Support
|
268
324
|
|
269
|
-
|
325
|
+
[Issues](https://github.com/richpeck/exception_handler/issues)
|
270
326
|
|
271
|
-
|
327
|
+
---
|
272
328
|
|
273
|
-
|
329
|
+
## Changelog
|
274
330
|
|
275
|
-
|
331
|
+
### [0.7.5](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)
|
332
|
+
- [x] [HTTP status layouts](#layouts)
|
276
333
|
|
277
|
-
### [
|
278
|
-
- [
|
279
|
-
- [
|
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
|
-
- [ ]
|
282
|
-
- [x] [
|
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
|
-
### [
|
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
|
-
### [
|
296
|
-
- [x]
|
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
|
-
### [
|
307
|
-
- [x] New config system
|
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
|
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
|
-
[
|
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
|
-
[
|
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]:
|
342
|
-
[rubygems]:
|
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]:
|
345
|
-
[fork]:
|
346
|
-
[pull]:
|
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
|
<!-- ################################### -->
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module ExceptionHandler
|
2
|
-
class
|
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[
|
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)
|
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: [:
|
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
|
176
|
+
ActionDispatch::ExceptionWrapper.new(request.env, exception).status_code
|
177
177
|
end
|
178
178
|
|
179
179
|
# => Server Response ("Not Found" etc)
|
File without changes
|
@@ -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
|
-
|
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
|
data/exception_handler.gemspec
CHANGED
data/lib/exception_handler.rb
CHANGED
@@ -3,16 +3,29 @@
|
|
3
3
|
|
4
4
|
module ExceptionHandler
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# =>
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
26
|
+
# => Table Name
|
27
|
+
# => Has to be "errors" because "exceptions" is a reserved word
|
28
|
+
TABLE = :errors
|
21
29
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
# =>
|
65
|
-
raise
|
66
|
-
|
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 <<
|
24
|
+
config.assets.precompile << "exception_handler.css"
|
23
25
|
|
24
26
|
#########################################################
|
25
27
|
#########################################################
|
26
28
|
|
27
|
-
# =>
|
28
|
-
# =>
|
29
|
-
|
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
|
-
|
35
|
-
|
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
|
-
|
8
|
+
#Views
|
9
|
+
VIEWS = %w(views controllers models assets)
|
23
10
|
|
24
|
-
|
25
|
-
|
11
|
+
#Options
|
12
|
+
class_option :files, aliases: "-v", default: VIEWS, type: :array, desc: "Select file types (views, models, controllers, assets)"
|
26
13
|
|
27
|
-
#
|
28
|
-
|
14
|
+
#Needed to reference files
|
15
|
+
source_root File.expand_path("../../../../app", __FILE__)
|
29
16
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
17
|
+
###########################################
|
18
|
+
###########################################
|
19
|
+
###########################################
|
34
20
|
|
35
|
-
#
|
36
|
-
|
37
|
-
|
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
|
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.
|
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-
|
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/
|
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/
|
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
|
Binary file
|
@@ -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
|