gaffe 0.0.1 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in gaffe.gemspec
4
2
  gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2013, Mirego
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ - Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ - Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ - Neither the name of the Mirego nor the names of its contributors may
13
+ be used to endorse or promote products derived from this software without
14
+ specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,29 +1,88 @@
1
1
  # Gaffe
2
2
 
3
- TODO: Write a gem description
3
+ Gaffe handles Rails error pages in a clean, simple way.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add this line to your applications Gemfile:
8
8
 
9
- gem 'gaffe'
9
+ ```ruby
10
+ gem 'gaffe'
11
+ ```
10
12
 
11
- And then execute:
13
+ ## Usage
12
14
 
13
- $ bundle
15
+ The easiest way to use Gaffe is with an initializer:
14
16
 
15
- Or install it yourself as:
17
+ ```ruby
18
+ # config/initializers/gaffe.rb
19
+ Gaffe.enable!
20
+ ```
16
21
 
17
- $ gem install gaffe
22
+ ### Custom controller
18
23
 
19
- ## Usage
24
+ However, if you want to use your own controller:
25
+
26
+ ```ruby
27
+ # config/initializers/gaffe.rb
28
+ Gaffe.configure do |config|
29
+ config.errors_controller = ErrorsController
30
+ end
31
+
32
+ Gaffe.enable!
33
+ ```
34
+
35
+ The only required thing to do in your custom controller is to include the `Gaffe::Errors` module.
36
+
37
+ Only `show` will be called so you might want to overwrite it. You might also want to get rid of filters and other stuff.
38
+
39
+ ```ruby
40
+ class ErrorsController < ApplicationController
41
+ include Gaffe::Errors
42
+ skip_before_filter :ensure_current_user
43
+
44
+ def show
45
+ # The following variables are available:
46
+ @exception # The encountered exception (Eg. `#<ActiveRecord::NotFound …>`)
47
+ @status_code # The status code we should return (Eg. `404`)
48
+ @rescue_response # The "standard" name for the status code (Eg. `:not_found`)
49
+ end
50
+ end
51
+ ```
52
+
53
+ ### Custom views
54
+
55
+ You can (and should!) also use your own views. You just have to create a layout:
56
+
57
+ ```
58
+ <!-- app/views/layouts/error.html.erb -->
59
+ <h1>Error!</h1>
60
+ <%= yield %>
61
+ ```
62
+
63
+ And create a different view for [each possible error rescue response](https://github.com/rails/rails/blob/f9ceefd3b9c3cea2460a89799156f2c532c4491c/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb). For example, for `404` errors:
64
+
65
+ ```
66
+ <!-- app/views/errors/not_found.html.erb -->
67
+ <p>This page does not exist.</p>
68
+ ```
69
+
70
+ ### Custom exceptions
71
+
72
+ If your application is raising custom exceptions (through gems or your code)
73
+ and you want to render specific views when it happens, you can map them to
74
+ specific rescue responses.
75
+
76
+ ```ruby
77
+ # config/application.rb
78
+ config.action_dispatch.rescue_responses.merge!('CanCan::AccessDenied' => :forbidden)
79
+ config.action_dispatch.rescue_responses.merge!('MyCustomException' => :not_acceptable)
80
+ ```
81
+
82
+ ## License
20
83
 
21
- TODO: Write usage instructions here
84
+ `Gaffe` is © 2013 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/gaffe/blob/master/LICENSE.md) file.
22
85
 
23
- ## Contributing
86
+ ## About Mirego
24
87
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
88
+ Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We proudly built mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development").
@@ -0,0 +1 @@
1
+ Forbidden
@@ -0,0 +1 @@
1
+ Internal Server Error
@@ -0,0 +1 @@
1
+ Not Found
@@ -0,0 +1 @@
1
+ Unauthorized
@@ -0,0 +1,16 @@
1
+ <h1>Error!</h1>
2
+
3
+ <p>This is an error page brought to you by <strong>Gaffe</strong>.</p>
4
+
5
+ <hr>
6
+
7
+ <%= yield %>
8
+
9
+ <hr>
10
+
11
+ <p>You can overwrite this page by creating these files:</p>
12
+
13
+ <pre>
14
+ <code><%= Rails.root.join('app', 'views', 'layouts', "error.html.[handler]") %></code>
15
+ <code><%= Rails.root.join('app', 'views', 'errors', "#{@rescue_response.to_s}.html.[handler]") %></code>
16
+ </pre>
data/gaffe.gemspec CHANGED
@@ -4,20 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'gaffe/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "gaffe"
7
+ spec.name = 'gaffe'
8
8
  spec.version = Gaffe::VERSION
9
- spec.authors = ["Rémi Prévost"]
10
- spec.email = ["rprevost@mirego.com"]
11
- spec.description = ""
12
- spec.summary = ""
13
- spec.homepage = ""
14
- spec.license = "MIT"
9
+ spec.authors = ['Rémi Prévost', 'Simon Prévost']
10
+ spec.email = ['rprevost@mirego.com', 'sprevost@mirego.com']
11
+ spec.description = 'Gaffe handles Rails error pages in a clean, simple way.'
12
+ spec.summary = 'Gaffe handles Rails error pages in a clean, simple way.'
13
+ spec.homepage = 'https://github.com/mirego/gaffe'
14
+ spec.license = "BSD 3-Clause"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+
24
+ spec.add_dependency 'actionpack', '>= 3.0.0'
23
25
  end
@@ -0,0 +1,29 @@
1
+ module Gaffe
2
+ module Errors
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_filter :fetch_exception, only: %w(show)
7
+ before_filter :append_view_paths
8
+ layout 'error'
9
+ end
10
+
11
+ def show
12
+ render "errors/#{@rescue_response}", status: @status_code
13
+ end
14
+
15
+ protected
16
+
17
+ def fetch_exception
18
+ @exception = env['action_dispatch.exception']
19
+ @status_code = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
20
+ @rescue_response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
21
+ end
22
+
23
+ private
24
+
25
+ def append_view_paths
26
+ append_view_path File.expand_path('../../../app/views', __FILE__)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module Gaffe
2
+ class ErrorsController < ::ApplicationController
3
+ include Errors
4
+ end
5
+ end
data/lib/gaffe/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gaffe
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1'
3
3
  end
data/lib/gaffe.rb CHANGED
@@ -1,5 +1,27 @@
1
- require "gaffe/version"
1
+ require 'gaffe/version'
2
+ require 'gaffe/errors'
2
3
 
3
4
  module Gaffe
4
- # Your code goes here...
5
+ def self.configure
6
+ yield configuration
7
+ end
8
+
9
+ def self.configuration
10
+ @configuration ||= OpenStruct.new
11
+ end
12
+
13
+ def self.errors_controller
14
+ @errors_controller ||= (configuration.errors_controller || builtin_errors_controller)
15
+ end
16
+
17
+ def self.builtin_errors_controller
18
+ require 'gaffe/errors_controller'
19
+ Gaffe::ErrorsController
20
+ end
21
+
22
+ def self.enable!
23
+ Rails.application.config.exceptions_app = lambda do |env|
24
+ Gaffe.errors_controller.action(:show).call(env)
25
+ end
26
+ end
5
27
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaffe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: '0.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rémi Prévost
9
+ - Simon Prévost
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-07-12 00:00:00.000000000 Z
13
+ date: 2013-07-13 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler
@@ -43,24 +44,48 @@ dependencies:
43
44
  - - ! '>='
44
45
  - !ruby/object:Gem::Version
45
46
  version: '0'
46
- description: ''
47
+ - !ruby/object:Gem::Dependency
48
+ name: actionpack
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
63
+ description: Gaffe handles Rails error pages in a clean, simple way.
47
64
  email:
48
65
  - rprevost@mirego.com
66
+ - sprevost@mirego.com
49
67
  executables: []
50
68
  extensions: []
51
69
  extra_rdoc_files: []
52
70
  files:
53
71
  - .gitignore
54
72
  - Gemfile
55
- - LICENSE.txt
73
+ - LICENSE.md
56
74
  - README.md
57
75
  - Rakefile
76
+ - app/views/errors/forbidden.html.erb
77
+ - app/views/errors/internal_server_error.html.erb
78
+ - app/views/errors/not_found.html.erb
79
+ - app/views/errors/unauthorized.html.erb
80
+ - app/views/layouts/error.html.erb
58
81
  - gaffe.gemspec
59
82
  - lib/gaffe.rb
83
+ - lib/gaffe/errors.rb
84
+ - lib/gaffe/errors_controller.rb
60
85
  - lib/gaffe/version.rb
61
- homepage: ''
86
+ homepage: https://github.com/mirego/gaffe
62
87
  licenses:
63
- - MIT
88
+ - BSD 3-Clause
64
89
  post_install_message:
65
90
  rdoc_options: []
66
91
  require_paths:
@@ -71,16 +96,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
96
  - - ! '>='
72
97
  - !ruby/object:Gem::Version
73
98
  version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 39176632371721851
74
102
  required_rubygems_version: !ruby/object:Gem::Requirement
75
103
  none: false
76
104
  requirements:
77
105
  - - ! '>='
78
106
  - !ruby/object:Gem::Version
79
107
  version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 39176632371721851
80
111
  requirements: []
81
112
  rubyforge_project:
82
113
  rubygems_version: 1.8.23
83
114
  signing_key:
84
115
  specification_version: 3
85
- summary: ''
116
+ summary: Gaffe handles Rails error pages in a clean, simple way.
86
117
  test_files: []
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Rémi Prévost
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.