rexception 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24a25113fbbb43426828f6de6097162baf65e3f9
4
- data.tar.gz: d443721593818ec4de8f75af7ca4f9d1205e2dc0
3
+ metadata.gz: 0f1548316fad12668415072e05a723299ebce5b2
4
+ data.tar.gz: 624cc7489047fec4d5778db9ec3519ae492b402a
5
5
  SHA512:
6
- metadata.gz: 44abab142291c6969576e3fb188975f8516ec407b343de6c036f864399f4b71c2f06d002fde6cfb67c6e698ada03fba59b7821f6713c834387e3453c10316398
7
- data.tar.gz: 4eb25ffdd6c3e064c65297de1ac5b2a394d3afa1ab2ac30500ee86026afb772507face10a3be3914b3575942fe3eb85e77e07da605ee91e9db83c8b74ce97bb2
6
+ metadata.gz: d059c5e073e1e4c761cf73dd0f6b963e5b0b6fa6780723ced702512c8e8711b110db07ef1701c73c4dadc18f3bce592536469a6ccab3d2add0b726918634ecda
7
+ data.tar.gz: dcc9fe3ff08f459b831eba0976f3f8e74608a1242d8afb5caa13418c96eeeee30aa6ed3aee4775d6e4aa82408d7bfc61a5b9c04e310aaa6a49ac012251a9dfb7
@@ -0,0 +1,5 @@
1
+ .bundle/
2
+ pkg/
3
+ spec/dummy/log/
4
+ spec/dummy/tmp/
5
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,61 @@
1
+ # Rexception
2
+
3
+ [![Build Status](https://travis-ci.org/kami30k/rexception.svg)](https://travis-ci.org/kami30k/rexception)
4
+ [![Gem Version](https://badge.fury.io/rb/rexception.svg)](http://badge.fury.io/rb/rexception)
5
+
6
+ Rexception is a Rails plugin that renders error pages dynamically, such as 403, 404, 500, and so on.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'rexception'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```
19
+ $ bundle
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ The simplest way, just add `app/views/errors/application.html.erb`.
25
+ That's it, and Rails application render it when raise any errors.
26
+
27
+ If you placed specific views, such as `forbidden.html.erb` or `not_found.html.erb`, Rexception prefers these views to `application.html.erb`.
28
+ (File name is see also: [ActionDispatch::ExceptionWrapper.rescue_responses](https://github.com/rails/rails/blob/083f657c0f1990e980d33f89f44d8943a9270475/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb#L9-L19))
29
+
30
+ And you can specify layout file name, directory name to place views, and custom exceptions.
31
+ Create `config/initializers/rexception.rb` and add following lines:
32
+
33
+ ```ruby
34
+ Rexception.configure do |config|
35
+ # Layout file name to use for rendering error page.
36
+ config.layout = 'application'
37
+
38
+ # Directory name where you place error pages.
39
+ config.errors_dir = 'errors_dir'
40
+
41
+ # Pairs of custom exceptions and statuses.
42
+ config.rescue_responses = {
43
+ 'CustomException' => :not_found
44
+ }
45
+ end
46
+
47
+ ```
48
+
49
+ In `development` mode, you should add this line to `config/environments/development.rb` to render error pages:
50
+
51
+ ```ruby
52
+ config.consider_all_requests_local = false
53
+ ```
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( https://github.com/kami30k/rexception/fork )
58
+ 2. Create your feature branch (git checkout -b my-new-feature)
59
+ 3. Commit your changes (git commit -am 'Add some feature')
60
+ 4. Push to the branch (git push origin my-new-feature)
61
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,3 +1,7 @@
1
1
  require 'bundler'
2
+ require 'rspec/core/rake_task'
2
3
 
3
4
  Bundler::GemHelper.install_tasks
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
@@ -1,17 +1,34 @@
1
1
  require 'rexception/version'
2
- require 'rexception/controller'
3
2
  require 'rexception/railtie' if defined?(Rails)
4
3
 
5
4
  module Rexception
6
- autoload :Setting, 'rexception/setting'
5
+ autoload :ExceptionsController, 'rexception/exceptions_controller'
7
6
 
8
7
  class << self
9
- def setup(&block)
10
- Setting.instance.setup(&block)
8
+ # Layout file name to use for rendering error page.
9
+ #
10
+ # @return [String]
11
+ attr_accessor :layout
12
+
13
+ # Directory name where you place error pages.
14
+ #
15
+ # @return [String]
16
+ attr_accessor :errors_dir
17
+
18
+ # Pairs of custom exceptions and statuses.
19
+ #
20
+ # @return [Hash{String => Symbol}]
21
+ def rescue_responses=(rescue_responses)
22
+ ActionDispatch::ExceptionWrapper.rescue_responses.merge!(rescue_responses)
11
23
  end
12
24
 
13
- def setting
14
- Setting.instance
25
+ # Configuring module attributes by initializer.
26
+ #
27
+ # @yield Rexception
28
+ def configure
29
+ yield self
15
30
  end
16
31
  end
17
32
  end
33
+
34
+ require 'rexception/config'
@@ -0,0 +1,12 @@
1
+ Rexception.configure do |config|
2
+ # Layout file name to use for rendering error page.
3
+ config.layout = 'application'
4
+
5
+ # Directory name where you place error pages.
6
+ config.errors_dir = 'errors_dir'
7
+
8
+ # Pairs of custom exceptions and statuses.
9
+ config.rescue_responses = {
10
+ 'CustomException' => :not_found
11
+ }
12
+ end
@@ -10,20 +10,24 @@ module Rexception
10
10
  RUBY
11
11
  end
12
12
 
13
- layout -> { setting.layout }
13
+ layout -> { layout }
14
14
 
15
15
  private
16
16
 
17
17
  def view(status = status())
18
- "#{setting.errors_dir}/#{status}"
18
+ "#{errors_dir}/#{status}"
19
19
  end
20
20
 
21
21
  def status
22
22
  self.class.status(env)
23
23
  end
24
24
 
25
- def setting
26
- Rexception.setting
25
+ def layout
26
+ Rexception.layout
27
+ end
28
+
29
+ def errors_dir
30
+ Rexception.errors_dir
27
31
  end
28
32
 
29
33
  class << self
@@ -1,5 +1,3 @@
1
- require 'rails'
2
-
3
1
  module Rexception
4
2
  class Railtie < Rails::Railtie
5
3
  initializer 'rexception' do |app|
@@ -1,3 +1,3 @@
1
1
  module Rexception
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,21 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'rexception/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'rexception'
7
+ s.version = Rexception::VERSION
8
+ s.authors = 'kami'
9
+ s.email = 'kami30k@gmail.com'
10
+ s.homepage = 'https://github.com/kami30k/rexception'
11
+ s.summary = 'Rendering error pages for Rails application.'
12
+ s.description = 'Rendering error pages for Rails application.'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files -z`.split("\x0")
16
+
17
+ s.add_dependency 'rails'
18
+
19
+ s.add_development_dependency 'rspec-rails'
20
+ s.add_development_dependency 'capybara'
21
+ end
@@ -0,0 +1 @@
1
+ Application Error
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,48 @@
1
+ $:.unshift File.expand_path('../../../lib', __FILE__)
2
+
3
+ require 'action_controller/railtie'
4
+ require 'action_view/railtie'
5
+
6
+ require 'rexception'
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ config.secret_token = 'abcdefghijklmnopqrstuvwxyz0123456789'
11
+ config.session_store :cookie_store, key: '_dummy_session'
12
+ config.eager_load = false
13
+ config.active_support.deprecation = :log
14
+ end
15
+ end
16
+
17
+ Dummy::Application.initialize!
18
+
19
+ Dummy::Application.routes.draw do
20
+ get '/application_error', to: 'errors#application_error'
21
+ get '/forbidden', to: 'errors#forbidden'
22
+ end
23
+
24
+ class CustomException < StandardError
25
+ end
26
+
27
+ class ApplicationController < ActionController::Base
28
+ end
29
+
30
+ class ErrorsController < ApplicationController
31
+ def application_error
32
+ raise Exception
33
+ end
34
+
35
+ def forbidden
36
+ raise CustomException
37
+ end
38
+ end
39
+
40
+ Rexception.configure do |config|
41
+ config.layout = 'layout'
42
+
43
+ config.errors_dir = 'errors_dir'
44
+
45
+ config.rescue_responses = {
46
+ 'CustomException' => :forbidden
47
+ }
48
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_PATH = File.expand_path('../../application', __FILE__)
4
+
5
+ require 'rails/commands'
@@ -0,0 +1 @@
1
+ run Rails.application
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Error pages' do
4
+ shared_examples_for 'error page' do |path, code, content|
5
+ it "should return #{code}" do
6
+ visit path
7
+
8
+ expect(page.status_code).to eq code
9
+ expect(page).to have_content content
10
+ end
11
+ end
12
+
13
+ context 'access to 403 page' do
14
+ it_behaves_like 'error page', '/forbidden', 403, 'Forbidden'
15
+ end
16
+
17
+ context 'access to 404 page' do
18
+ it_behaves_like 'error page', '/not_found', 404, 'Not Found'
19
+ end
20
+
21
+ context 'access to 500 page' do
22
+ it_behaves_like 'error page', '/application_error', 500, 'Application Error'
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'dummy/application'
2
+
3
+ require 'rspec/rails'
4
+ require 'capybara/rails'
5
+ require 'capybara/rspec'
6
+
7
+ RSpec.configure do |config|
8
+ config.include Capybara::DSL
9
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexception
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kami
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.0
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Rendering error pages for Rails application.
56
- email:
57
- - kami30k@gmail.com
56
+ email: kami30k@gmail.com
58
57
  executables: []
59
58
  extensions: []
60
59
  extra_rdoc_files: []
61
60
  files:
61
+ - ".gitignore"
62
+ - ".rspec"
63
+ - ".travis.yml"
64
+ - Gemfile
62
65
  - MIT-LICENSE
66
+ - README.md
63
67
  - Rakefile
64
68
  - lib/rexception.rb
65
- - lib/rexception/controller.rb
69
+ - lib/rexception/config.rb
70
+ - lib/rexception/exceptions_controller.rb
66
71
  - lib/rexception/railtie.rb
67
- - lib/rexception/setting.rb
68
72
  - lib/rexception/version.rb
73
+ - rexception.gemspec
74
+ - spec/dummy/app/views/errors_dir/application.html.erb
75
+ - spec/dummy/app/views/errors_dir/forbidden.html.erb
76
+ - spec/dummy/app/views/errors_dir/not_found.html.erb
77
+ - spec/dummy/app/views/layouts/layout.html.erb
78
+ - spec/dummy/application.rb
79
+ - spec/dummy/bin/rails
80
+ - spec/dummy/config.ru
81
+ - spec/requests/error_pages_spec.rb
82
+ - spec/spec_helper.rb
69
83
  homepage: https://github.com/kami30k/rexception
70
84
  licenses:
71
85
  - MIT
@@ -86,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
100
  version: '0'
87
101
  requirements: []
88
102
  rubyforge_project:
89
- rubygems_version: 2.2.2
103
+ rubygems_version: 2.4.5
90
104
  signing_key:
91
105
  specification_version: 4
92
106
  summary: Rendering error pages for Rails application.
@@ -1,31 +0,0 @@
1
- require 'singleton'
2
-
3
- module Rexception
4
- class Setting
5
- include Singleton
6
-
7
- attr_accessor :layout
8
- attr_accessor :errors_dir
9
-
10
- def initialize
11
- defaults.each { |k, v| instance_variable_set("@#{k}", v) }
12
- end
13
-
14
- def setup
15
- yield self
16
- end
17
-
18
- def rescue_responses=(rescue_responses)
19
- ActionDispatch::ExceptionWrapper.rescue_responses.merge!(rescue_responses)
20
- end
21
-
22
- private
23
-
24
- def defaults
25
- @defaults ||= {
26
- layout: 'application',
27
- errors_dir: 'errors'
28
- }
29
- end
30
- end
31
- end