Skip to content

Commit 04fffc9

Browse files
committed
0.8 Update
1 parent d8eca36 commit 04fffc9

File tree

94 files changed

+2191
-215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+2191
-215
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tmp
2121
*.a
2222
mkmf.log
2323
*.tmp
24+
.rspec_status
2425

2526
##########################################################
2627
##########################################################

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format progress
2+
--color
3+
--require spec_helper

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
language: ruby
12
rvm:
23
- 2.2.4
3-
- 2.3.2
4-
- 2.4.0
4+
- 2.3.7
5+
- 2.4.4
6+
- 2.5.1
57
- ruby-head

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ group :test do
1010
gem 'coveralls', require: false
1111
end
1212

13+
# => Required for Windows
14+
gem 'tzinfo-data' if Gem.win_platform? # => TZInfo For Windows
15+
1316
###########################################

README.md

Lines changed: 323 additions & 126 deletions
Large diffs are not rendered by default.

app/assets/stylesheets/exception_handler.css.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515
*/
1616
/* ---------------------------------------------------- */
1717
/* ---------------------------------------------------- */
18+
/*
19+
*= link_tree ../images
20+
*/
21+
/* ---------------------------------------------------- */
22+
/* ---------------------------------------------------- */
1823
/* ---------------------------------------------------- */

app/assets/stylesheets/styles/_base.css.erb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
/* ---------------------------------------------------- */
55
/* ---------------------------------------------------- */
66

7-
/*
8-
*= link_tree ../../images
9-
*/
10-
11-
/* ---------------------------------------------------- */
12-
/* ---------------------------------------------------- */
13-
147
* { margin: 0; }
158
html, body { height: 100%; }
169
html {
1710
height: 100%;
1811
color: #fff;
19-
background: #010008 url(<%= asset_url("exception_handler/bg.jpg") %>) top left no-repeat;
12+
background: #121212;
2013
background-size: 100% 100%;
2114
box-sizing: border-box;
2215
}

app/assets/stylesheets/styles/_exception.css.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
border-color: rgba(255,255,255,0.09);
5454
border-style: solid
5555
}
56-
.exception:hover { cursor: pointer; }
56+
.exception:hover { cursor: pointer; }
57+
.exception:hover:after { text-decoration: underline; }
5758

5859
.exception span:before {
5960
display: block;

app/controllers/exception_handler/exceptions_controller.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ class ExceptionsController < ApplicationController
3636
layout :layout
3737

3838
####################
39-
# Action #
39+
# Actions #
4040
####################
4141

42+
# => General Show Functionality
43+
# => Introduced new "action" config option in 0.8.0.0
4244
def show
4345
respond_with @exception, status: @exception.status
4446
end
@@ -48,8 +50,13 @@ def show
4850

4951
private
5052

51-
def layout
52-
ExceptionHandler.config.layouts[@exception.status]
53+
# => Pulls from Exception class
54+
# => Spanner in the works is nil
55+
# => .present? validates against empty strings (IE a string is present)
56+
# => .nil? validates to see if the returned data is "nil"
57+
# => nil required to facilitate inheritance of the layout w/ ApplicationController
58+
def layout option = ExceptionHandler.config.options(@exception.status, :layout)
59+
(option.present? || option.nil?) ? option : 'exception'
5360
end
5461

5562
##################################

app/models/exception_handler/exception.rb

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,13 @@ module ExceptionHandler
1010
# => Attributes
1111
# => Determine schema etc
1212
ATTRS = %i(class_name status message trace target referrer params user_agent)
13-
14-
# => Exceptions to be rescued by ExceptionHandler
15-
EXCEPTIONS_TO_BE_RESCUED = [ActionController::RoutingError, AbstractController::ActionNotFound].tap do |list|
16-
list << ActiveRecord::RecordNotFound if defined?(ActiveRecord)
17-
list << Mongoid::Errors::DocumentNotFound if defined?(Mongoid)
18-
end
1913

2014
############################################################
2115
############################################################
2216

2317
# => Class (inheritance dependent on whether db option is available)
24-
self::Exception = Class.new(
25-
(ExceptionHandler.config.try(:db) && defined?(ActiveRecord)) ? ActiveRecord::Base : Object
26-
) do
18+
self::Exception =
19+
Class.new( (ExceptionHandler.config.try(:db) && defined?(ActiveRecord)) ? ActiveRecord::Base : Object ) do
2720

2821
# => Include individual elements
2922
# => Only required if no db present (no ActiveRecord)
@@ -97,15 +90,14 @@ def self.table_name
9790
# => Email
9891
# => after_initialize invoked after .new method called
9992
# => Should have been after_create but user may not save
100-
after_initialize Proc.new { |e| ExceptionHandler::ExceptionMailer.new_exception(e).deliver } if ExceptionHandler.config.try(:email).try(:is_a?, String)
93+
after_initialize -> (e) { ExceptionHandler::ExceptionMailer.new_exception(e).deliver }, if: :email? # => see bottom of file
10194

10295
# => Attributes
10396
attr_accessor :request, :klass, :exception, :description
10497
attr_accessor *ATTRS unless ExceptionHandler.config.try(:db)
10598

10699
# => Validations
107-
validates :klass, exclusion: { in: EXCEPTIONS_TO_BE_RESCUED, message: "%{value}" }, if: -> { referer.blank? } # => might need full Proc syntax
108-
validates :user_agent, format: { without: Regexp.new( BOTS.join("|"), Regexp::IGNORECASE ) }
100+
validates :user_agent, format: { without: Regexp.new( BOTS.join("|"), Regexp::IGNORECASE ) }
109101

110102
##################################
111103
##################################
@@ -114,21 +106,22 @@ def self.table_name
114106
# Virtual
115107
####################################
116108

109+
# => Exception (virtual)
110+
# => Basis on which all the class is built
111+
def exception
112+
request.env['action_dispatch.exception']
113+
end
114+
117115
# => Klass
118116
# => Used for validation (needs to be cleaned up in 0.7.0)
119117
def klass
120118
exception.class
121119
end
122120

123-
# => Exception (virtual)
124-
def exception
125-
request.env['action_dispatch.exception']
126-
end
127-
128121
# => Description
129122
def description
130123
I18n.with_options scope: [:exception_handler], message: message, status: status do |i18n|
131-
i18n.t response, default: Rack::Utils::HTTP_STATUS_CODES[status] || status
124+
i18n.t response, default: Rack::Utils::HTTP_STATUS_CODES[status]
132125
end
133126
end
134127

@@ -143,7 +136,7 @@ def class_name
143136

144137
# => Message
145138
def message
146-
exception.message
139+
exception ? exception.message : Rack::Utils::HTTP_STATUS_CODES[status]
147140
end
148141

149142
# => Trace
@@ -181,7 +174,7 @@ def user_agent
181174

182175
# => Status code (404, 500 etc)
183176
def status
184-
ActionDispatch::ExceptionWrapper.new(request.env, exception).status_code
177+
exception ? ActionDispatch::ExceptionWrapper.new(request.env, exception).try(:status_code) : request.env["PATH_INFO"][1..-1].to_i
185178
end
186179

187180
# => Server Response ("Not Found" etc)
@@ -192,6 +185,14 @@ def response
192185
##################################
193186
##################################
194187

188+
private
189+
190+
# => Email
191+
# => should be on the same line as after_initialize but too long
192+
def email?
193+
ExceptionHandler.config.try(:email).try(:is_a?, String) && ExceptionHandler.config.options(status, :notification) != false
194+
end
195+
195196
end
196197
end
197198

0 commit comments

Comments
 (0)