vidibus-routing_error 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,143 @@
1
+ # Vidibus::RoutingError
2
+
3
+ Catches ActionController::RoutingError which does not work with Rails 3
4
+ out of the box. It basically catches the exception on Rack-level and
5
+ re-raises it on application-level.
6
+
7
+ This gem is part of [Vidibus](http://vidibus.org), an open source toolset
8
+ for building distributed (video) applications.
9
+
10
+
11
+ ## Please Read This
12
+
13
+ In most cases it will be sufficient to add a catch-all route. But don't put
14
+ it just at the end of `routes.rb` because that will disable all routes defined
15
+ by gems your application uses. Instead, append the route in `application.rb`:
16
+
17
+ ```ruby
18
+ module PutYourApplicationNameHere
19
+ class Application < Rails::Application
20
+ # Catch 404s
21
+ config.after_initialize do |app|
22
+ app.routes.append{match '*path', :to => 'application#rescue_404'}
23
+ end
24
+ end
25
+ end
26
+ ```
27
+
28
+ If that won't work for any reason, you may still use this gem. :)
29
+
30
+
31
+ ## Addressed Problem
32
+
33
+ Since Rails 3 is based on Rack, catching a 404 error in your Application
34
+ controller does not work as expected. The underlying problem is discussed
35
+ [here](https://rails.lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror).
36
+
37
+
38
+ ## Installation
39
+
40
+ Add the dependency to the Gemfile of your application:
41
+
42
+ ```ruby
43
+ gem 'vidibus-routing_error'
44
+ ```
45
+
46
+ Then call bundle install on your console.
47
+
48
+
49
+ ## Usage
50
+
51
+ With this gem installed, you are able to handle errors like in past versions
52
+ of Rails:
53
+
54
+ ```ruby
55
+ class ApplicationController < ActionController::Base
56
+ rescue_from ActionController::RoutingError, :with => :rescue_404
57
+
58
+ def rescue_404
59
+ # do something
60
+ # IMPORTANT: If you modify this method, you have to restart the server.
61
+ end
62
+ end
63
+ ```
64
+
65
+ Keep in mind that you have to restart your server when changing the rescue-method!
66
+
67
+
68
+ ## Underlying Mechanics
69
+
70
+ This gem implants the middleware `Vidibus::RoutingError::Rack` into your Rails stack
71
+ right after `ActionDispatch::ShowExceptions` which returns a 404 response if no
72
+ matching route was found for the current request.
73
+
74
+ `Vidibus::RoutingError::Rack` catches the 404 status and redirects internally to the route
75
+ `'/routing_error'` which is provided by this gem.
76
+
77
+ Through this route the method `RoutingErrorController#rescue` gets called which then raises
78
+ an `ActionController::RoutingError` on application level so you can rescue this error.
79
+
80
+
81
+ ### Custom controller for error handling
82
+
83
+ If you want to handle the error in a specific controller, you can also route the path
84
+ `'/routing_error'` in `routes.rb` to it:
85
+
86
+ ```ruby
87
+ match 'routing_error' => 'my_controller#rescue_404'
88
+ ```
89
+
90
+ The failing URI will be available in the environment variable:
91
+
92
+ ```ruby
93
+ env['vidibus-routing_error.request_uri']
94
+ ```
95
+
96
+
97
+ ## Possible Issues
98
+
99
+ ### Catch-all Route
100
+
101
+ If your application has a catch-route in `routes.rb`, this gem won't work, because
102
+ routes provided by engines will be added after any existing routes. If you don't
103
+ need a catch-all route for other purposes than rescuing from routing errors, you can
104
+ savely remove it.
105
+
106
+
107
+ ### Class Caching
108
+
109
+ Depending on the structure of your application, you might get an error in development
110
+ like this:
111
+
112
+ ```
113
+ TypeError (User can't be referred)
114
+ ```
115
+
116
+ This error is caused by some caching-reloading madness: The middleware implanted by
117
+ this gem is cached. But in development, your classes usually aren't. Thus some classes
118
+ may not be available under certain circumstances, e.g. if you are using before filters
119
+ for user authentication provided by some engine. You should be able to get rid of
120
+ the error above by turning on class caching. Try it (and restart the server afterwards):
121
+
122
+ ```ruby
123
+ # development.rb
124
+ config.cache_classes = true
125
+ ```
126
+
127
+ If the error is gone, you're lucky as I am. But since it is not feasible to cache classes
128
+ in development, turn off class caching again and explicitly require the class that couldn't
129
+ be referred. In my case, it's the user class:
130
+
131
+ ```ruby
132
+ # top of development.rb
133
+ require 'app/models/user'
134
+ ```
135
+
136
+ ## Copyright
137
+
138
+ &copy; 2010-2012 Andre Pankratz. See LICENSE for details.
139
+
140
+
141
+ ## Thank you!
142
+
143
+ The development of this gem was sponsored by Käuferportal: http://www.kaeuferportal.de
data/Rakefile CHANGED
@@ -1,47 +1,17 @@
1
- require "rubygems"
2
- require "rake"
1
+ require 'bundler'
2
+ require 'rdoc/task'
3
+ require 'rspec'
4
+ require 'rspec/core/rake_task'
3
5
 
4
- begin
5
- require "jeweler"
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "vidibus-routing_error"
8
- gem.summary = %Q{Catches ActionController::RoutingError in Rails 3.}
9
- gem.description = %Q{Catches ActionController::RoutingError and sends it to a custom method.}
10
- gem.email = "andre@vidibus.com"
11
- gem.homepage = "http://github.com/vidibus/vidibus-routing_error"
12
- gem.authors = ["Andre Pankratz"]
13
- gem.add_development_dependency "rspec"
14
- gem.add_development_dependency "relevance-rcov"
15
- gem.add_development_dependency "rr"
16
- gem.add_dependency "rails", "~> 3.0.0"
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- Jeweler::GemcutterTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
- end
23
-
24
- require "spec/rake/spectask"
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << "lib" << "spec"
27
- spec.spec_files = FileList["spec/**/*_spec.rb"]
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |t|
31
- t.spec_files = FileList["spec/vidibus/**/*_spec.rb"]
32
- t.rcov = true
33
- t.rcov_opts = ["--exclude", "^spec,/gems/"]
34
- end
6
+ Bundler::GemHelper.install_tasks
35
7
 
36
- task :spec => :check_dependencies
37
- task :default => :spec
8
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
9
+ require 'vidibus/routing_error/version'
38
10
 
39
- require "rake/rdoctask"
40
11
  Rake::RDocTask.new do |rdoc|
41
- version = File.exist?("VERSION") ? File.read("VERSION") : ""
42
- rdoc.rdoc_dir = "rdoc"
43
- rdoc.title = "vidibus-routing_error #{version}"
44
- rdoc.rdoc_files.include("README*")
45
- rdoc.rdoc_files.include("lib/**/*.rb")
46
- rdoc.options << "--charset=utf-8"
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = "vidibus-routing_error #{Vidibus::RoutingError::VERSION}"
14
+ rdoc.rdoc_files.include('README*')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ rdoc.options << '--charset=utf-8'
47
17
  end
@@ -9,7 +9,7 @@ class RoutingErrorController < ApplicationController
9
9
  # end
10
10
  #
11
11
  def rescue
12
- env["REQUEST_URI"] = env["vidibus-routing_error.request_uri"]
13
- raise ActionController::RoutingError, "No route matches #{env["REQUEST_URI"].inspect}"
12
+ env['REQUEST_URI'] = env['vidibus-routing_error.request_uri']
13
+ raise ActionController::RoutingError, "No route matches #{env['REQUEST_URI'].inspect}"
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
- match "routing_error" => "routing_error#rescue"
2
+ match 'routing_error' => 'routing_error#rescue'
3
3
  end
@@ -1,10 +1,9 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), "..", "lib", "vidibus"))
2
- require "routing_error/rack"
1
+ require 'vidibus/routing_error/rack'
3
2
 
4
3
  module Vidibus::RoutingError
5
4
  class Engine < ::Rails::Engine
6
5
  unless Rails.env.test?
7
- config.app_middleware.insert_after("ActionDispatch::ShowExceptions", "Vidibus::RoutingError::Rack")
6
+ config.app_middleware.insert_after('ActionDispatch::ShowExceptions', 'Vidibus::RoutingError::Rack')
8
7
  end
9
8
  end
10
- end
9
+ end
@@ -8,8 +8,8 @@ module Vidibus
8
8
  def call(env)
9
9
  response = @app.call(env)
10
10
  if response[0] == 404
11
- env["vidibus-routing_error.request_uri"] = env["REQUEST_URI"]
12
- env["PATH_INFO"] = env["REQUEST_URI"] = "/routing_error"
11
+ env['vidibus-routing_error.request_uri'] = env['REQUEST_URI']
12
+ env['PATH_INFO'] = env['REQUEST_URI'] = '/routing_error'
13
13
  @app.call(env)
14
14
  else
15
15
  response
@@ -0,0 +1,5 @@
1
+ module Vidibus
2
+ module RoutingError
3
+ VERSION = '0.2.2'
4
+ end
5
+ end
metadata CHANGED
@@ -1,136 +1,85 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: vidibus-routing_error
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andre Pankratz
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-04 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-02-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &2153329160 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: relevance-rcov
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2153329160
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &2153328620 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: rr
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2153328620
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ requirement: &2153327940 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
61
44
  type: :development
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: rails
65
45
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ~>
70
- - !ruby/object:Gem::Version
71
- hash: 7
72
- segments:
73
- - 3
74
- - 0
75
- - 0
76
- version: 3.0.0
77
- type: :runtime
78
- version_requirements: *id004
46
+ version_requirements: *2153327940
79
47
  description: Catches ActionController::RoutingError and sends it to a custom method.
80
48
  email: andre@vidibus.com
81
49
  executables: []
82
-
83
50
  extensions: []
84
-
85
- extra_rdoc_files:
86
- - LICENSE
87
- - README.rdoc
88
- files:
89
- - .document
90
- - LICENSE
91
- - README.rdoc
92
- - Rakefile
93
- - VERSION
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/vidibus/routing_error/rack.rb
54
+ - lib/vidibus/routing_error/version.rb
55
+ - lib/vidibus-routing_error.rb
94
56
  - app/controllers/routing_error_controller.rb
95
57
  - config/routes.rb
96
- - lib/vidibus-routing_error.rb
97
- - lib/vidibus/routing_error/rack.rb
98
- - spec/spec.opts
99
- - spec/spec_helper.rb
100
- - vidibus-routing_error.gemspec
101
- has_rdoc: true
102
- homepage: http://github.com/vidibus/vidibus-routing_error
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ homepage: https://github.com/vidibus/vidibus-routing_error
103
62
  licenses: []
104
-
105
63
  post_install_message:
106
64
  rdoc_options: []
107
-
108
- require_paths:
65
+ require_paths:
109
66
  - lib
110
- required_ruby_version: !ruby/object:Gem::Requirement
67
+ required_ruby_version: !ruby/object:Gem::Requirement
111
68
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
119
- required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
74
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 3
125
- segments:
126
- - 0
127
- version: "0"
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.3.6
128
79
  requirements: []
129
-
130
- rubyforge_project:
131
- rubygems_version: 1.6.2
80
+ rubyforge_project: vidibus-routing_error
81
+ rubygems_version: 1.8.11
132
82
  signing_key:
133
83
  specification_version: 3
134
- summary: Catches ActionController::RoutingError in Rails 3.
135
- test_files:
136
- - spec/spec_helper.rb
84
+ summary: Catches ActionController::RoutingError in Rails 3
85
+ test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
@@ -1,108 +0,0 @@
1
- = Vidibus::RoutingError
2
-
3
- Catches ActionController::RoutingError which does not work with Rails 3
4
- out of the box. It basically catches the exception on Rack-level and
5
- re-raises it on application-level.
6
-
7
- This gem is part of the open source service-oriented {video
8
- framework}[http://vidibus.org] Vidibus.
9
-
10
-
11
- == Addressed Problem
12
-
13
- Since Rails 3 is based on Rack, catching a 404 error in your Application
14
- controller does not work as expected. The underlying problem is discussed
15
- {here}[https://rails.lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror].
16
-
17
- An easy but insufficient fix for this issue is to define a catch-all route
18
- at the end of your routes.rb:
19
-
20
- match "*path" => "application#rescue_404"
21
-
22
- <b>But beware of the major drawback!</b> If your application relies on engines that
23
- extend your app with their own routes, things will break because those
24
- routes will never get fired.
25
-
26
- With this gem, all your routing problems should be gone.
27
-
28
-
29
- == Installation
30
-
31
- Add the dependency to the Gemfile of your application:
32
-
33
- gem "vidibus-routing_error"
34
-
35
- Then call bundle install on your console.
36
-
37
-
38
- == Usage
39
-
40
- With this gem installed, you are able to handle errors like in past versions
41
- of Rails:
42
-
43
- class ApplicationController < ActionController::Base
44
- rescue_from ActionController::RoutingError, :with => :rescue_404
45
-
46
- def rescue_404
47
- # do something
48
- # IMPORTANT: If you modify this method, you have to restart the server.
49
- end
50
- end
51
-
52
- Keep in mind that you have to restart your server when changing the rescue-method!
53
-
54
-
55
- == Underlying Mechanics
56
-
57
- This gem implants the middleware Vidibus::RoutingError::Rack into your Rails stack
58
- right after ActionDispatch::ShowExceptions which returns a 404 response if no
59
- matching route was found for the current request.
60
-
61
- Vidibus::RoutingError::Rack catches the 404 status and redirects internally to the route
62
- /routing_error which is provided by this gem.
63
-
64
- Through this route the method RoutingErrorController#rescue gets called which then raises
65
- a ActionController::RoutingError on application level so you can rescue this error.
66
-
67
-
68
- == Possible Issues
69
-
70
- === Catch-all Route
71
-
72
- If your application has a catch-route, this gem won't work, because routes provided by
73
- engines will be added after any existing routes. If you don't need a catch-all route for
74
- other purposes than rescuing from routing errors, you can savely remove it.
75
-
76
-
77
- === Class Caching
78
-
79
- Depending on the structure of your application, you might get an error in development
80
- like this:
81
-
82
- TypeError (User can't be referred)
83
-
84
- This error is caused by some caching-reloading madness: The middleware implanted by
85
- this gem is cached. But in development, your classes usually aren't. Thus some classes
86
- may not be available under certain circumstances, e.g. if you are using before filters
87
- for user authentication provided by some engine. You should be able to get rid of
88
- the error above by turning on class caching. Try it (and restart the server afterwards):
89
-
90
- # development.rb
91
- config.cache_classes = true
92
-
93
- If the error is gone, you're lucky as I am. But since it is not feasible to cache classes
94
- in development, turn off class caching again and explicitly require the class that couldn't
95
- be referred. In my case, it's the user class:
96
-
97
- # top of development.rb
98
- require "app/models/user"
99
-
100
-
101
- == Copyright
102
-
103
- Copyright (c) 2010 Andre Pankratz. See LICENSE for details.
104
-
105
-
106
- == Thank you!
107
-
108
- The development of this gem was sponsored by Käuferportal: http://www.kaeuferportal.de
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.1
@@ -1,2 +0,0 @@
1
- --color
2
- --format nested
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
-
4
- require "rubygems"
5
- require "active_support/core_ext"
6
- require "spec"
7
- require "rr"
8
- require "vidibus-routing_error"
9
-
10
- Spec::Runner.configure do |config|
11
- config.mock_with RR::Adapters::Rspec
12
- end
@@ -1,62 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{vidibus-routing_error}
8
- s.version = "0.2.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Andre Pankratz"]
12
- s.date = %q{2011-05-04}
13
- s.description = %q{Catches ActionController::RoutingError and sends it to a custom method.}
14
- s.email = %q{andre@vidibus.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "app/controllers/routing_error_controller.rb",
26
- "config/routes.rb",
27
- "lib/vidibus-routing_error.rb",
28
- "lib/vidibus/routing_error/rack.rb",
29
- "spec/spec.opts",
30
- "spec/spec_helper.rb",
31
- "vidibus-routing_error.gemspec"
32
- ]
33
- s.homepage = %q{http://github.com/vidibus/vidibus-routing_error}
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.6.2}
36
- s.summary = %q{Catches ActionController::RoutingError in Rails 3.}
37
- s.test_files = [
38
- "spec/spec_helper.rb"
39
- ]
40
-
41
- if s.respond_to? :specification_version then
42
- s.specification_version = 3
43
-
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_development_dependency(%q<rspec>, [">= 0"])
46
- s.add_development_dependency(%q<relevance-rcov>, [">= 0"])
47
- s.add_development_dependency(%q<rr>, [">= 0"])
48
- s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"])
49
- else
50
- s.add_dependency(%q<rspec>, [">= 0"])
51
- s.add_dependency(%q<relevance-rcov>, [">= 0"])
52
- s.add_dependency(%q<rr>, [">= 0"])
53
- s.add_dependency(%q<rails>, ["~> 3.0.0"])
54
- end
55
- else
56
- s.add_dependency(%q<rspec>, [">= 0"])
57
- s.add_dependency(%q<relevance-rcov>, [">= 0"])
58
- s.add_dependency(%q<rr>, [">= 0"])
59
- s.add_dependency(%q<rails>, ["~> 3.0.0"])
60
- end
61
- end
62
-