exception_handler 0.7.5 → 0.8.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +5 -5
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +51 -33
  4. data/.rspec +3 -4
  5. data/.slugignore +7 -0
  6. data/.travis.yml +13 -5
  7. data/Gemfile +16 -13
  8. data/README.md +643 -443
  9. data/Rakefile +7 -7
  10. data/app/assets/stylesheets/exception_handler.css.erb +23 -18
  11. data/app/assets/stylesheets/styles/_base.css.erb +28 -35
  12. data/app/assets/stylesheets/styles/_exception.css.erb +106 -105
  13. data/app/assets/stylesheets/styles/_footer.css.erb +24 -24
  14. data/app/assets/stylesheets/styles/_responsive.css +5 -5
  15. data/app/controllers/exception_handler/exceptions_controller.rb +66 -55
  16. data/app/mailers/exception_handler/exception_mailer.rb +17 -17
  17. data/app/models/exception_handler/exception.rb +200 -191
  18. data/app/views/exception_handler/exceptions/show.html.erb +3 -3
  19. data/app/views/exception_handler/mailers/layout.haml +8 -8
  20. data/app/views/exception_handler/mailers/layout.text.erb +1 -1
  21. data/app/views/exception_handler/mailers/new_exception.erb +4 -4
  22. data/app/views/layouts/exception.html.erb +32 -27
  23. data/app/views/layouts/mailer.html.erb +5 -0
  24. data/app/views/layouts/mailer.text.erb +1 -0
  25. data/config/locales/exception_handler.en.yml +28 -29
  26. data/config/routes.rb +42 -0
  27. data/db/migrate/000000_create_errors.rb +34 -34
  28. data/exception_handler.gemspec +64 -80
  29. data/lib/exception_handler.rb +56 -45
  30. data/lib/exception_handler/config.rb +185 -103
  31. data/lib/exception_handler/engine.rb +78 -60
  32. data/lib/exception_handler/version.rb +25 -0
  33. data/lib/generators/exception_handler/views_generator.rb +33 -33
  34. data/spec/controllers/controller_spec.rb +107 -0
  35. data/spec/dummy/.rspec +1 -0
  36. data/spec/dummy/.ruby-version +1 -0
  37. data/spec/dummy/Rakefile +6 -6
  38. data/spec/dummy/app/assets/config/manifest.js +3 -4
  39. data/spec/dummy/app/assets/javascripts/application.js +15 -13
  40. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +15 -15
  42. data/spec/dummy/app/channels/application_cable/channel.rb +4 -5
  43. data/spec/dummy/app/channels/application_cable/connection.rb +4 -5
  44. data/spec/dummy/app/controllers/application_controller.rb +2 -5
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  46. data/spec/dummy/app/jobs/application_job.rb +2 -2
  47. data/spec/dummy/app/mailers/application_mailer.rb +4 -4
  48. data/spec/dummy/app/models/application_record.rb +3 -3
  49. data/spec/dummy/app/views/layouts/application.html.erb +15 -15
  50. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -13
  51. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -1
  52. data/spec/dummy/bin/bundle +3 -3
  53. data/spec/dummy/bin/rails +4 -4
  54. data/spec/dummy/bin/rake +4 -4
  55. data/spec/dummy/bin/setup +36 -34
  56. data/spec/dummy/bin/update +31 -29
  57. data/spec/dummy/bin/yarn +11 -0
  58. data/spec/dummy/config.ru +5 -8
  59. data/spec/dummy/config/application.rb +18 -21
  60. data/spec/dummy/config/boot.rb +5 -5
  61. data/spec/dummy/config/cable.yml +10 -10
  62. data/spec/dummy/config/database.yml +25 -25
  63. data/spec/dummy/config/environment.rb +5 -5
  64. data/spec/dummy/config/environments/development.rb +61 -62
  65. data/spec/dummy/config/environments/production.rb +94 -87
  66. data/spec/dummy/config/environments/test.rb +46 -42
  67. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -6
  68. data/spec/dummy/config/initializers/assets.rb +14 -11
  69. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  70. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  71. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -5
  72. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  73. data/spec/dummy/config/initializers/inflections.rb +16 -16
  74. data/spec/dummy/config/initializers/mime_types.rb +4 -4
  75. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  76. data/spec/dummy/config/locales/en.yml +33 -23
  77. data/spec/dummy/config/puma.rb +34 -47
  78. data/spec/dummy/config/routes.rb +3 -6
  79. data/spec/dummy/config/storage.yml +34 -0
  80. data/spec/dummy/package.json +5 -0
  81. data/spec/dummy/public/404.html +67 -67
  82. data/spec/dummy/public/422.html +67 -67
  83. data/spec/dummy/public/500.html +66 -66
  84. data/spec/dummy/spec/rails_helper.rb +57 -0
  85. data/spec/dummy/spec/spec_helper.rb +100 -0
  86. data/spec/dummy/storage/.keep +0 -0
  87. data/spec/features/asset_spec.rb +61 -0
  88. data/spec/features/config_spec.rb +51 -0
  89. data/spec/features/engine_spec.rb +180 -0
  90. data/spec/mailers/mailer_spec.rb +26 -0
  91. data/spec/models/model_spec.rb +26 -0
  92. data/spec/routing/routing_spec.rb +85 -0
  93. data/spec/spec_helper.rb +101 -55
  94. data/spec/views/views_spec.rb +29 -0
  95. metadata +54 -28
  96. data/.gitattributes +0 -1
  97. data/LICENSE.txt +0 -22
  98. data/app/assets/images/exception_handler/bg.jpg +0 -0
  99. data/app/assets/images/exception_handler/bg_overlay.png +0 -0
  100. data/spec/database.yml +0 -3
  101. data/spec/dummy/app/assets/javascripts/cable.coffee +0 -11
  102. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +0 -6
  103. data/spec/dummy/config/initializers/callback_terminator.rb +0 -6
  104. data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +0 -4
  105. data/spec/dummy/config/initializers/request_forgery_protection.rb +0 -4
  106. data/spec/dummy/config/initializers/session_store.rb +0 -3
  107. data/spec/dummy/config/secrets.yml +0 -22
  108. data/spec/exception_handler.rb +0 -22
  109. data/spec/exception_handler/exception_controller_spec.rb +0 -18
@@ -1,103 +1,185 @@
1
- ###########################################
2
-
3
- # Refs
4
- # http://stackoverflow.com/questions/10584638/setting-up-configuration-settings-when-writing-a-gem
5
- # http://robots.thoughtbot.com/mygem-configure-block
6
-
7
- ###########################################
8
-
9
- module ExceptionHandler
10
- class Config
11
-
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
20
-
21
- ###########################################
22
- ###########################################
23
- ###########################################
24
- ###########################################
25
-
26
- # => Table Name
27
- # => Has to be "errors" because "exceptions" is a reserved word
28
- TABLE = :errors
29
-
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
- }
39
-
40
- ###########################################
41
- ###########################################
42
-
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
- }
70
-
71
- ###########################################
72
- ###########################################
73
-
74
- # => Init
75
- # => Merges DEFAULTS to values, creates instances vars (for attr_accessor)
76
- def initialize values
77
-
78
- # => Vars
79
- DEFAULTS.deep_merge!(values || {}).each do |k,v|
80
- instance_variable_set("@#{k}",v)
81
- end
82
-
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)
86
- end
87
-
88
- ###########################################
89
- ###########################################
90
-
91
- # => DB
92
- # => If config db = "true", use TABLE constant
93
- def db
94
- @db == true ? TABLE : @db.try(:parameterize, separator: "_")
95
- end
96
-
97
- ###########################################
98
- ###########################################
99
- ###########################################
100
- ###########################################
101
-
102
- end
103
- end
1
+ ###########################################
2
+ ###########################################
3
+ ## _____ __ _ ##
4
+ ## / __ \ / _(_) ##
5
+ ## | / \/ ___ _ __ | |_ _ __ _ ##
6
+ ## | | / _ \| '_ \| _| |/ _` | ##
7
+ ## | \__/\ (_) | | | | | | | (_| | ##
8
+ ## \____/\___/|_| |_|_| |_|\__, | ##
9
+ ## __/ | ##
10
+ ## |___/ ##
11
+ ###########################################
12
+ ###########################################
13
+
14
+ # Refs
15
+ # http://stackoverflow.com/questions/10584638/setting-up-configuration-settings-when-writing-a-gem
16
+ # http://robots.thoughtbot.com/mygem-configure-block
17
+
18
+ ###########################################
19
+ ###########################################
20
+
21
+ module ExceptionHandler
22
+ class Config
23
+
24
+ # => Instace Objects
25
+ # => ExceptionHandler.config.dev
26
+ # => ExceptionHandler.config.db
27
+ # => ExceptionHandler.config.email
28
+ # => ExceptionHandler.config.social
29
+ # => ExceptionHandler.config.layouts -> will need to be deprecated
30
+ # => ExceptionHandler.config.exceptions
31
+ # => ExceptionHandler.config.custom_exceptions
32
+ attr_accessor :dev, :db, :email, :social, :layouts, :exceptions, :custom_exceptions
33
+
34
+ ###########################################
35
+ ###########################################
36
+ ###########################################
37
+ ###########################################
38
+
39
+ # => Table Name
40
+ # => Has to be "errors" because "exceptions" is a reserved word
41
+ TABLE = :errors
42
+
43
+ ###########################################
44
+ ###########################################
45
+
46
+ # => Social URLs
47
+ # => Extracted from "social" block
48
+ SOCIAL =
49
+ ActiveSupport::HashWithIndifferentAccess.new({
50
+ facebook: "https://www.facebook.com",
51
+ twitter: "https://www.twitter.com",
52
+ youtube: "https://www.youtube.com/user",
53
+ linkedin: "https://www.linkedin.com/company",
54
+ fusion: "https://www.frontlinefusion.com"
55
+ })
56
+
57
+ ###########################################
58
+ ###########################################
59
+
60
+ # => Defaults
61
+ # => http://stackoverflow.com/a/8917301/1143732
62
+ DEFAULTS =
63
+ ActiveSupport::HashWithIndifferentAccess.new({
64
+
65
+ # => General options
66
+ dev: nil, # => defaults to "false" for dev mode
67
+ db: nil, # => defaults to :errors if true, else use "table_name" / :table_name
68
+ email: nil, # => requires string email and ActionMailer
69
+
70
+ # => Used in "exception" layout
71
+ social: {
72
+ facebook: nil,
73
+ twitter: nil,
74
+ youtube: nil,
75
+ linkedin: nil,
76
+ fusion: nil,
77
+ },
78
+
79
+ # => Defaults for exceptions. Override with specific status codes
80
+ # => Please note these are all STRINGS
81
+ exceptions: {
82
+
83
+ # => 4xx/5xx base standard
84
+ # => :all provide block customization (overrides 4xx/5xx)
85
+ # => specific provides individual (overrides all)
86
+
87
+ # => 4xx Errors (resource not found)
88
+ # => https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors
89
+ '4xx' => {
90
+ layout: nil
91
+ # notification: true #(this is for emails - it's true by default - only if you have email inputted)
92
+ # action: ____, (this is general)
93
+ # background: (can define custom background for exceptions layout if required)
94
+ },
95
+
96
+ # => 5xx Errors (server error)
97
+ # => https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors
98
+ '5xx' => {
99
+ layout: 'exception'
100
+ # notification: true (this is for emails - it's true by default - only if you have email inputted)
101
+ # action: _____, (this is general)
102
+ # background: (can define custom background for exceptions layout if required)
103
+ }
104
+ },
105
+
106
+ # Deprecated
107
+ #layouts: {
108
+ # => nil inherits from ApplicationController
109
+ # => 4xx errors should be nil
110
+ # => 5xx errors should be "exception" but can be nil if explicitly defined
111
+ #500 => 'exception',
112
+ #501 => 'exception',
113
+ #502 => 'exception',
114
+ #503 => 'exception',
115
+ #504 => 'exception',
116
+ #505 => 'exception',
117
+ #507 => 'exception',
118
+ #510 => 'exception'
119
+ #},
120
+
121
+ # => If you want to map your own classes to HTTP errors
122
+ # => use this...
123
+ custom_exceptions: {
124
+ #'ActionController::RoutingError' => :not_found # => example
125
+ }
126
+
127
+ })
128
+
129
+ ###########################################
130
+ ###########################################
131
+
132
+ # => Constructor
133
+ # => Merges DEFAULTS to values, creates instances vars (for attr_accessor)
134
+ def initialize values
135
+
136
+ # => Vars
137
+ DEFAULTS.deep_merge!(values || {}).each do |k,v|
138
+ instance_variable_set("@#{k}",v)
139
+ end
140
+
141
+ # => Validation
142
+ raise ExceptionHandler::Error, "Email Not Valid" if @email && !@email.nil? && !@email.is_a?(String)
143
+ raise ExceptionHandler::Error, "Migration Required → \"#{db}\" doesn't exist" if @db && !ActiveRecord::Base.connection.table_exists?(db) && (File.basename($0) != "rake" && !ARGV.include?("db:migrate"))
144
+
145
+ end
146
+
147
+ ###########################################
148
+ ###########################################
149
+
150
+ # => DB
151
+ # => If config db = "true", use TABLE constant
152
+ def db
153
+ @db == true ? TABLE : @db.try(:parameterize, separator: "_")
154
+ end
155
+
156
+ ###########################################
157
+ ###########################################
158
+
159
+ # => Options
160
+ # => Requires argument
161
+ def options status, pluck=nil
162
+
163
+ # => Structure from old + new setup
164
+ # => 1. layouts => [500, '500']
165
+ # => 2. exceptions => [500, '500' 'all', '4xx'/'5xx']
166
+ { layouts: [status, status.to_s], # old + new
167
+ exceptions: [status, status.to_s, 'all', status.to_s.first + 'xx'] }.each do |key,array|
168
+
169
+ # => Array
170
+ # => https://stackoverflow.com/a/26877095/1143732
171
+ array.each do |specific|
172
+ item = self.send(key).try(:[], specific)
173
+ return (item.is_a?(Hash) ? ActiveSupport::HashWithIndifferentAccess.new(item)[pluck.try(:to_sym)] : item) if item.present? || (self.send(key).try(:has_key?, specific) && item.nil?) #if result exists and it has a value (including nil)
174
+ end
175
+
176
+ end
177
+ end
178
+
179
+ ###########################################
180
+ ###########################################
181
+ ###########################################
182
+ ###########################################
183
+
184
+ end
185
+ end
@@ -1,60 +1,78 @@
1
- module ExceptionHandler
2
- class Engine < Rails::Engine
3
-
4
- # => Rails default MIME types:
5
- # => http://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to#14-Rails-defined-Mime-Types
6
-
7
- #########################################################
8
- #########################################################
9
- #########################################################
10
- #########################################################
11
-
12
- # => Wraps helpers in ExceptionHandler module
13
- # => http://guides.rubyonrails.org/engines.html#inside-an-engine
14
- # => http://stackoverflow.com/questions/31877839/accessing-helpers-from-the-parent-app-in-an-isolated-rails-engine
15
- isolate_namespace ExceptionHandler
16
-
17
- # => Tests
18
- config.generators do |g|
19
- g.test_framework :rspec
20
- end
21
-
22
- # => Assets
23
- # => For Sprockets 4, had to include link_tree in exception_handler.css
24
- config.assets.precompile << "exception_handler.css"
25
-
26
- #########################################################
27
- #########################################################
28
-
29
- # => Config
30
- # => Builds lib/exception_handler/config.rb
31
- config.before_initialize do |app|
32
- ExceptionHandler.config ||= ExceptionHandler::Config.new config.try(:exception_handler)
33
- end
34
-
35
- #########################################################
36
- #########################################################
37
-
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) }
42
- app.config.consider_all_requests_local = !ExceptionHandler.config.try(:dev) if Rails.env.development?
43
- end
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
52
- end
53
-
54
- #########################################################
55
- #########################################################
56
- #########################################################
57
- #########################################################
58
-
59
- end
60
- end
1
+ ###########################################
2
+ ###########################################
3
+ ## _____ _ ##
4
+ ## | ___| (_) ##
5
+ ## | |__ _ __ __ _ _ _ __ ___ ##
6
+ ## | __| '_ \ / _` | | '_ \ / _ \ ##
7
+ ## | |__| | | | (_| | | | | | __/ ##
8
+ ## \____/_| |_|\__, |_|_| |_|\___| ##
9
+ ## __/ | ##
10
+ ## |___/ ##
11
+ ###########################################
12
+ ###########################################
13
+
14
+ module ExceptionHandler
15
+ class Engine < Rails::Engine
16
+
17
+ # => Rails default MIME types:
18
+ # => http://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to#14-Rails-defined-Mime-Types
19
+
20
+ #########################################################
21
+ #########################################################
22
+
23
+ # => Wraps helpers in ExceptionHandler module
24
+ # => http://guides.rubyonrails.org/engines.html#inside-an-engine
25
+ # => http://stackoverflow.com/questions/31877839/accessing-helpers-from-the-parent-app-in-an-isolated-rails-engine
26
+ isolate_namespace ExceptionHandler
27
+
28
+ # => Tests
29
+ config.generators do |g|
30
+ g.test_framework :rspec
31
+ end
32
+
33
+ # => Assets
34
+ # => For Sprockets 4, had to include link_tree in exception_handler.css
35
+ config.assets.precompile << "exception_handler.css"
36
+
37
+ #########################################################
38
+ #########################################################
39
+
40
+ # => Config
41
+ # => Builds lib/exception_handler/config.rb
42
+ # => config.before_initialize do |app| => Needs to be fixed for ActiveRecord::Base
43
+ # => to support later version of config, "with_indifferent_access" used in config.rb
44
+ initializer :exception_handler_config, before: "better_errors.configure_rails_initialization" do |app|
45
+ ExceptionHandler.config ||= ExceptionHandler::Config.new config.try(:exception_handler)
46
+ end
47
+
48
+ #########################################################
49
+ #########################################################
50
+
51
+ # => Middleware
52
+ # => This should be config.before_initialize but because ActiveRecord is not initialized, cannot check for table
53
+ initializer :exception_handler, before: "better_errors.configure_rails_initialization" do |app|
54
+ app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionsController.action(:show).call(env) }
55
+ app.config.consider_all_requests_local = !ExceptionHandler.config.try(:dev) if Rails.env.development? || Rails.env.test?
56
+ end
57
+
58
+ # => Custom Exceptions
59
+ # => This just mimicks standard Rails behaviour
60
+ # => Look for "config.action_dispatch.rescue_responses" for more info)
61
+ initializer :exception_handler_custom_exceptions do |app|
62
+ app.config.action_dispatch.rescue_responses.merge! ExceptionHandler.config.custom_exceptions if ExceptionHandler.config.custom_exceptions
63
+ end
64
+
65
+ # => Migrations
66
+ # => This has to be kept in an initializer (to access app)
67
+ # => https://blog.pivotal.io/labs/labs/leave-your-migrations-in-your-rails-engines
68
+ initializer :migration_paths do |app|
69
+ config.paths["db/migrate"].expanded.each do |expanded_path|
70
+ app.config.paths["db/migrate"] << expanded_path if ExceptionHandler.config.try(:db)
71
+ end
72
+ end
73
+
74
+ #########################################################
75
+ #########################################################
76
+
77
+ end
78
+ end
@@ -0,0 +1,25 @@
1
+ ###########################################
2
+ ###########################################
3
+ ## _ _ _ ##
4
+ ## | | | | (_) ##
5
+ ## | | | | ___ _ __ ___ _ ___ _ __ ##
6
+ ## | | | |/ _ \ '__/ __| |/ _ \| '_ \ ##
7
+ ## \ \_/ / __/ | \__ \ | (_) | | | | ##
8
+ ## \___/ \___|_| |___/_|\___/|_| |_| ##
9
+ ## ##
10
+ ###########################################
11
+ ###########################################
12
+
13
+ module ExceptionHandler
14
+ module VERSION
15
+ MAJOR = 0
16
+ MINOR = 8
17
+ TINY = 0
18
+ PRE = 1 # "alpha"
19
+
20
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
21
+ end
22
+ end
23
+
24
+ ###########################################
25
+ ###########################################