mosaic-errors 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,48 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+
41
+ # For vim:
42
+ #*.swp
43
+
44
+ # For redcar:
45
+ #.redcar
46
+
47
+ # For rubinius:
48
+ #*.rbc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+ # Specify your gem's dependencies in mosaic-errors.gemspec
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Kel Stopper
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ mosaic-errors
2
+ =============
3
+
4
+ Gem to add custom error pages to your rails 3 app.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add to Gemfile:
10
+
11
+ gem 'mosaic-errors'
12
+
13
+ Then...
14
+
15
+ bundle install
16
+
17
+ Usage
18
+ -----
19
+
20
+ ### Auto Install
21
+
22
+ Use the generator to copy the error files over and add the route to catch all routing errors:
23
+
24
+ rails generator mosaic_errors
25
+
26
+ Add to ApplicationController:
27
+
28
+ include Mosaic::Errors
29
+
30
+ Ensure the provided route goes very last in your config/routes.rb file as it will catch anything that is not previously configured
31
+
32
+ ### Manual Install
33
+
34
+ Add to config/routes.rb:
35
+
36
+ match '*path', :to => 'application#routing_error'
37
+
38
+ Ensure the above route comes very last in your config/routes.rb file as it will catch anything that is not previously configured.
39
+
40
+ Create the folder app/views/errors and drop the files internal_server_error.html.haml & not_found.html.haml
41
+
42
+ Add to ApplicationController:
43
+
44
+ include Mosaic::Errors
45
+
46
+ Configuration
47
+ -------------
48
+
49
+ By default this gem will not display a stacktrace when something goes wrong. This can potentially be problematic when debugging an application so this behaviour can be overridden by adding the following to an initializer:
50
+
51
+ Mosaic::Errors.include_stack_trace!
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require "bundler/gem_tasks"
6
+
7
+ task :default => [:test]
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.pattern = 'test/*_test.rb'
11
+ t.verbose = true
12
+ end
13
+
14
+ Rake::Task[:test].comment = "Run all tests"
15
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
File without changes
@@ -0,0 +1,13 @@
1
+ class ErrorPagesGenerator < Rails::Generators::Base
2
+ desc "adds error pages haml to the application and add routes"
3
+ source_root File.expand_path("../templates", __FILE__)
4
+
5
+ def copy_error_pages
6
+ copy_file "internal_server_error.html.haml", "app/views/errors/internal_server_error.html.haml"
7
+ copy_file "not_found.html.haml", "app/views/errors/not_found.html.haml"
8
+ end
9
+
10
+ def add_route
11
+ route "match '*path', :to => 'application#routing_error'"
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ %h1.server_error.error_page We're sorry...
2
+ %p.error_page There was an error with the page you requested.
@@ -0,0 +1,2 @@
1
+ %h1.not_found.error_page Page Not Found
2
+ %p.error_page You may have mistyped the address or the page may have moved.
@@ -0,0 +1,2 @@
1
+ STDERR.puts "WARNING: mosaic-errors will soon be deprecated - use Rails 3.2+ config.exception_app instead"
2
+ require 'mosaic/errors'
@@ -0,0 +1,66 @@
1
+ module Mosaic
2
+ module Errors
3
+ @@include_stack_trace = false
4
+
5
+ def self.include_stack_trace!
6
+ @@include_stack_trace = true
7
+ end
8
+
9
+ def self.included(controller)
10
+ controller.extend(ClassMethods)
11
+ controller.rescue_from Exception do |exception|
12
+ render_application_error_template_for_exception(exception)
13
+ Rails.logger.error exception.backtrace.join("\n") if include_stack_trace?
14
+ end
15
+ end
16
+
17
+ def routing_error
18
+ render_application_error_template :not_found
19
+ end
20
+
21
+ module ClassMethods
22
+ DEFAULT_RESCUE_RESPONSE = :internal_server_error
23
+
24
+ DEFAULT_RESCUE_RESPONSES = {
25
+ 'ActionController::RoutingError' => :not_found,
26
+ 'ActionController::UnknownAction' => :not_found,
27
+ 'ActiveRecord::RecordNotFound' => :not_found,
28
+ 'ActiveRecord::StaleObjectError' => :conflict,
29
+ 'ActiveRecord::RecordInvalid' => :unprocessable_entity,
30
+ 'ActiveRecord::RecordNotSaved' => :unprocessable_entity,
31
+ 'ActionController::MethodNotAllowed' => :method_not_allowed,
32
+ 'ActionController::NotImplemented' => :not_implemented,
33
+ 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity
34
+ }
35
+
36
+ def rescue_responses
37
+ @rescue_responses ||= Hash.new(DEFAULT_RESCUE_RESPONSE).merge(DEFAULT_RESCUE_RESPONSES)
38
+ end
39
+ end
40
+
41
+ protected
42
+ def render_application_error_template(status)
43
+ render :template => "errors/#{status}", :status => status
44
+ rescue ActionView::MissingTemplate
45
+ render :nothing => true, :status => status
46
+ end
47
+
48
+ def render_application_error_template_for_exception(exception)
49
+ status = self.class.rescue_responses[exception.class.name]
50
+ send_exception_notification(exception) if status == :internal_server_error || status == :not_found
51
+ render_application_error_template status
52
+ end
53
+
54
+ def send_exception_notification(exception)
55
+ if defined? notify_airbrake
56
+ notify_airbrake(exception)
57
+ elsif defined? notify_hoptoad
58
+ notify_hoptoad(exception)
59
+ end
60
+ end
61
+
62
+ def include_stack_trace?
63
+ @@include_stack_trace
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ module Mosaic
2
+ module Errors
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ STDERR.puts "WARNING: mosaic_errors is deprecated - change all instances of require 'mosaic_errors' to 'mosaic-errors'"
2
+ require 'mosaic-errors'
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mosaic/errors/version"
5
+ require "date"
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "mosaic-errors"
9
+ gem.version = Mosaic::Errors::VERSION
10
+ gem.date = Date.today.to_s
11
+
12
+ gem.summary = "Rails 3.x custom error page support."
13
+ gem.description = "A gem to simplify implementation of custom error pages in a Rails 3.x application."
14
+
15
+ gem.authors = ["Kel Stopper"]
16
+ gem.email = ["kel.stopper@mosaic.com"]
17
+ gem.homepage = "http://git.corp.mosaic.com/mosaiccis/mosaic-errors"
18
+
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ["lib"]
23
+
24
+ gem.add_runtime_dependency "haml", [">= 0"]
25
+
26
+ gem.add_development_dependency "rake", [">= 0"]
27
+ gem.add_development_dependency "shoulda", [">= 0"]
28
+ end
29
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'mosaic_errors'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMosaicErrors < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
File without changes
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mosaic-errors
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kel Stopper
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: haml
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: shoulda
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: A gem to simplify implementation of custom error pages in a Rails 3.x
63
+ application.
64
+ email:
65
+ - kel.stopper@mosaic.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .document
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - VERSION
77
+ - install.rb
78
+ - lib/generators/error_pages_generator.rb
79
+ - lib/generators/templates/internal_server_error.html.haml
80
+ - lib/generators/templates/not_found.html.haml
81
+ - lib/mosaic-errors.rb
82
+ - lib/mosaic/errors.rb
83
+ - lib/mosaic/errors/version.rb
84
+ - lib/mosaic_errors.rb
85
+ - mosaic-errors.gemspec
86
+ - test/helper.rb
87
+ - test/test_mosaic_errors.rb
88
+ - uninstall.rb
89
+ homepage: http://git.corp.mosaic.com/mosaiccis/mosaic-errors
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
102
+ - 0
103
+ hash: -4474960627516075816
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
111
+ - 0
112
+ hash: -4474960627516075816
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.23
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Rails 3.x custom error page support.
119
+ test_files:
120
+ - test/helper.rb
121
+ - test/test_mosaic_errors.rb