divert 0.8 → 0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +9 -3
- data/lib/divert.rb +10 -5
- data/lib/divert/configuration.rb +1 -0
- data/lib/divert/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f011293941b1d03cdd4a51c1b9ca0c409e51a93
|
4
|
+
data.tar.gz: de4f7bfe990bc1923b3f46b33faa0650b7a13e28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30db07838771b1297fdff9c751e78da8eff5a843064da2c5c074568ba9226523c559742b21ef1cabfa898a90631a8b525468d9bf3379b7ebb3e3d96d9d82d62f
|
7
|
+
data.tar.gz: 34203e63dbacb99b9ed8cc1bd69313053a15ccbd04fb103e75fce0e27318445edbabfbfec17ef1aedb86a9cb23e71f477444116035cc8f22b4179faa583491ae
|
data/README.rdoc
CHANGED
@@ -15,10 +15,16 @@ to the END of your routes file.
|
|
15
15
|
The route added catches anything so needs to go last.
|
16
16
|
|
17
17
|
Finally add:
|
18
|
-
|
19
|
-
|
18
|
+
class ApplicationController < ActionController::Base
|
19
|
+
include Divert
|
20
20
|
|
21
|
-
|
21
|
+
rescue_from ActiveRecord::RecordNotFound do |exception|
|
22
|
+
divert(request.env['PATH_INFO'])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
to your ApplicationController. The `rescue_from ActiveRecord::RecordNotFound` is optional, but allows Divert to recover from `Model.find(...)` errors with a redirect or 404.
|
26
|
+
|
27
|
+
It will not interfere with actions defined in the configured controller
|
22
28
|
or view files that don't have an action defined.
|
23
29
|
Cos it's nice like that.
|
24
30
|
|
data/lib/divert.rb
CHANGED
@@ -16,29 +16,34 @@ module Divert
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def action_missing path = nil
|
19
|
+
controller = Divert.configuration.controller || controller_name
|
19
20
|
|
20
21
|
path ||= params[:path]
|
21
22
|
if action_methods.include? path
|
22
23
|
send path and return
|
23
24
|
end
|
24
25
|
|
25
|
-
if template_exists?(path, [
|
26
|
-
render "#{
|
26
|
+
if template_exists?(path, [controller])
|
27
|
+
render "#{controller}/#{path}" and return
|
27
28
|
end
|
28
29
|
|
29
30
|
if Divert.configuration.save_to_db && (redirect = Redirect.hit(request.fullpath))
|
30
31
|
redirect_to redirect
|
31
32
|
else
|
32
|
-
unless template_exists? 'divert', [
|
33
|
-
render text:"Missing divert view: #{
|
33
|
+
unless template_exists? 'divert', [controller]
|
34
|
+
render text:"Missing divert view: #{controller}/divert.html.erb", :status => 404 and return
|
34
35
|
end
|
35
|
-
render "#{
|
36
|
+
render "#{controller}/divert", :status => 404 and return
|
36
37
|
end
|
37
38
|
end
|
39
|
+
|
40
|
+
alias_method :divert, :action_missing
|
38
41
|
end
|
39
42
|
|
40
43
|
class ActionDispatch::Routing::Mapper
|
41
44
|
def divert_with controller
|
45
|
+
# Set controller in configuration if not already set
|
46
|
+
Divert.configuration.controller ||= controller.to_s
|
42
47
|
get ':action' => controller.to_s
|
43
48
|
get '*path' => "#{controller}#action_missing", :format => false
|
44
49
|
end
|
data/lib/divert/configuration.rb
CHANGED
data/lib/divert/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: divert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Butler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.5.1
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Easily handle 404s and redirects with your rails app.
|
@@ -149,4 +149,3 @@ test_files:
|
|
149
149
|
- test/test_helper.rb
|
150
150
|
- test/unit/divert/redirect_test.rb
|
151
151
|
- test/unit/helpers/divert/redirects_helper_test.rb
|
152
|
-
has_rdoc:
|