divert 0.8 → 0.9

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: 16f5b5e662bdbbb632e00019f1e86196f5120875
4
- data.tar.gz: 5f92cbb7f07b6d07d95ff743681cc8461efae889
3
+ metadata.gz: 8f011293941b1d03cdd4a51c1b9ca0c409e51a93
4
+ data.tar.gz: de4f7bfe990bc1923b3f46b33faa0650b7a13e28
5
5
  SHA512:
6
- metadata.gz: 0a84c3129f19d06790c80321eca99a1dfa40cf35ec296cf120178412873205b7a78d1e22ab978724c0da88b08b68c25043b0991319092dfc28e49252e5ad01ed
7
- data.tar.gz: 1ba5c7dd0ed80d7d388aae650b1b45431732baf6d3c85e0e5a98a0863601b1334ea657ec99f577d9477927e2b43394861365bfc207af99f3220881bca98d9f55
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
- include Divert
19
- to the controller specified in the above route.
18
+ class ApplicationController < ActionController::Base
19
+ include Divert
20
20
 
21
- It will not interfere with actions defined in that controller
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, [controller_name])
26
- render "#{controller_name}/#{path}" and return
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', [controller_name]
33
- render text:"Missing divert view: #{controller_name}/divert.html.erb", :status => 404 and return
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 "#{controller_name}/divert", :status => 404 and return
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
@@ -1,6 +1,7 @@
1
1
  module Divert
2
2
  class Configuration
3
3
  attr_accessor :save_to_db
4
+ attr_accessor :controller
4
5
 
5
6
  def initialize
6
7
  @save_to_db = true
@@ -1,3 +1,3 @@
1
1
  module Divert
2
- VERSION = "0.8"
2
+ VERSION = "0.9"
3
3
  end
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.8'
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: 2015-09-24 00:00:00.000000000 Z
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.4.5
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: