routing-filter 0.3.1 → 0.4.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dae448fa20d77a3acbcc23bb63e5cb829b2cc3f8
4
+ data.tar.gz: e067c24c3c3644b82b5d62f1a373224ae3ef2276
5
+ SHA512:
6
+ metadata.gz: a02a85cad0a7030297ac0db2c857d29718612b1ae8b86f055a40c98bc84e49c2006f0e6d20ce1fd09f4bbe698b391a6f70e1e5689bc1d50e0705b5d07c26cbba
7
+ data.tar.gz: 5ea13645e8d27fcc89b600f2fe76c8ba2eeb08f5bb55b43bb88f5cf9b9e7cc1c8ea7007a949d17f16a6b5a2d6eca8282905b0a0e7a5b7b6c5de0ebc6417099d5
@@ -1,5 +1,7 @@
1
1
  # Routing Filter
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/svenfuchs/routing-filter.png)](http://travis-ci.org/svenfuchs/routing-filter)
4
+
3
5
  Routing filters wrap around the complex beast that the Rails routing system is
4
6
  to allow for unseen flexibility and power in Rails URL recognition and
5
7
  generation.
@@ -60,6 +62,17 @@ Filters can also accept options:
60
62
  filter :locale, :exclude => /^\/admin/
61
63
  end
62
64
 
65
+ ### Testing
66
+
67
+ RoutingFilter should not be enabled in functional tests by default since the Rails router gets
68
+ bypassed for most testcases. Having RoutingFilter enabled in this setup can cause missing parameters
69
+ in the test environment. Routing tests can/should re-enable RoutingFilter since the whole routing stack
70
+ gets executed for these testcases.
71
+
72
+ To disable RoutingFilter in your test suite add the following to your test_helper.rb / spec_helper.rb:
73
+
74
+ RoutingFilter.active = false
75
+
63
76
  ## Running the tests
64
77
 
65
78
  To run the tests against different dependencies [appraisal](https://github.com/thoughtbot/appraisal) is used.
@@ -0,0 +1,44 @@
1
+ require 'action_dispatch'
2
+ require 'active_support/core_ext/module/aliasing'
3
+ require 'active_support/core_ext/hash/reverse_merge'
4
+
5
+ mappers = [ActionDispatch::Routing::Mapper]
6
+ mappers << ActionDispatch::Routing::DeprecatedMapper if defined?(ActionDispatch::Routing::DeprecatedMapper)
7
+ mappers.each do |mapper|
8
+ mapper.class_eval do
9
+ def filter(*args)
10
+ @set.add_filters(*args)
11
+ end
12
+ end
13
+ end
14
+
15
+ ActionDispatch::Routing::RouteSet.class_eval do
16
+ def filters
17
+ @set.filters if @set
18
+ end
19
+
20
+ def add_filters(*names)
21
+ options = names.extract_options!
22
+ names.each { |name| filters.unshift(RoutingFilter.build(name, options)) }
23
+ end
24
+
25
+ def generate_with_filtering(options, recall = {})
26
+ # `around_generate` is destructive method and it breaks url. To avoid this, `dup` is required.
27
+ filters.run(:around_generate, options, &lambda{ generate_without_filtering(options, recall).map(&:dup) })
28
+ end
29
+ alias_method_chain :generate, :filtering
30
+
31
+ def clear_with_filtering!
32
+ filters.clear if filters
33
+ clear_without_filtering!
34
+ end
35
+ alias_method_chain :clear!, :filtering
36
+ end
37
+
38
+ ActionDispatch::Journey::Routes.class_eval do
39
+ def filters
40
+ @filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
41
+ end
42
+ end
43
+
44
+ require 'routing_filter/adapters/routers/journey'
@@ -1,15 +1,21 @@
1
- require 'journey/routes'
2
- require 'journey/router'
1
+ if defined?(ActionDispatch::Journey) # rails 4
2
+ journey = ActionDispatch::Journey
3
+ else # rails 3.2
4
+ require 'journey/routes'
5
+ require 'journey/router'
6
+ journey = Journey
7
+ end
3
8
 
4
- Journey::Routes.class_eval do
9
+ journey::Routes.class_eval do
5
10
  def filters
6
11
  @filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
7
12
  end
8
13
  end
9
14
 
10
- Journey::Router.class_eval do
15
+ journey::Router.class_eval do
11
16
  def find_routes_with_filtering env
12
17
  path, filter_parameters = env['PATH_INFO'], {}
18
+ original_path = path.dup
13
19
 
14
20
  @routes.filters.run(:around_recognize, path, env) do
15
21
  filter_parameters
@@ -17,6 +23,8 @@ Journey::Router.class_eval do
17
23
 
18
24
  find_routes_without_filtering(env).map do |match, parameters, route|
19
25
  [ match, parameters.merge(filter_parameters), route ]
26
+ end.tap do |match, parameters, route|
27
+ env['PATH_INFO'] = original_path # restore the original path
20
28
  end
21
29
  end
22
30
  alias_method_chain :find_routes, :filtering
@@ -27,7 +27,7 @@ module RoutingFilter
27
27
  def around_recognize(path, env, &block)
28
28
  page = extract_segment!(PAGINATION_SEGMENT, path)
29
29
  yield.tap do |params|
30
- params[:page] = page.to_i if page
30
+ params[:page] = page if page
31
31
  end
32
32
  end
33
33
 
@@ -1,3 +1,3 @@
1
1
  module RoutingFilter
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0.pre'
3
3
  end
metadata CHANGED
@@ -1,60 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routing-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: 0.4.0.pre
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sven Fuchs
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-28 00:00:00.000000000 Z
11
+ date: 2013-07-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: actionpack
16
- requirement: &2156259340 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *2156259340
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: appraisal
27
- requirement: &2156258620 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *2156258620
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: i18n
38
- requirement: &2156257900 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - '>='
42
46
  - !ruby/object:Gem::Version
43
47
  version: '0'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *2156257900
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: test_declarative
49
- requirement: &2156273620 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *2156273620
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  description: Routing filters wraps around the complex beast that the Rails routing
59
70
  system is, allowing for unseen flexibility and power in Rails URL recognition and
60
71
  generation.
@@ -67,42 +78,42 @@ files:
67
78
  - README.markdown
68
79
  - MIT-LICENSE
69
80
  - lib/routing/filter.rb
70
- - lib/routing-filter.rb
71
- - lib/routing_filter/adapters/rails_2.rb
72
- - lib/routing_filter/adapters/rails_3.rb
73
- - lib/routing_filter/adapters/routers/journey.rb
74
- - lib/routing_filter/adapters/routers/rack_mount.rb
75
81
  - lib/routing_filter/chain.rb
76
- - lib/routing_filter/filter.rb
77
- - lib/routing_filter/filters/extension.rb
78
82
  - lib/routing_filter/filters/locale.rb
79
- - lib/routing_filter/filters/pagination.rb
80
83
  - lib/routing_filter/filters/uuid.rb
84
+ - lib/routing_filter/filters/pagination.rb
85
+ - lib/routing_filter/filters/extension.rb
81
86
  - lib/routing_filter/version.rb
87
+ - lib/routing_filter/filter.rb
88
+ - lib/routing_filter/adapters/rails_3.rb
89
+ - lib/routing_filter/adapters/rails_4.rb
90
+ - lib/routing_filter/adapters/routers/journey.rb
91
+ - lib/routing_filter/adapters/routers/rack_mount.rb
92
+ - lib/routing_filter/adapters/rails_2.rb
82
93
  - lib/routing_filter.rb
94
+ - lib/routing-filter.rb
83
95
  homepage: http://github.com/svenfuchs/routing-filter
84
96
  licenses: []
97
+ metadata: {}
85
98
  post_install_message:
86
99
  rdoc_options: []
87
100
  require_paths:
88
101
  - lib
89
102
  required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
103
  requirements:
92
- - - ! '>='
104
+ - - '>='
93
105
  - !ruby/object:Gem::Version
94
106
  version: '0'
95
107
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
108
  requirements:
98
- - - ! '>='
109
+ - - '>'
99
110
  - !ruby/object:Gem::Version
100
- version: '0'
111
+ version: 1.3.1
101
112
  requirements: []
102
- rubyforge_project: ! '[none]'
103
- rubygems_version: 1.8.17
113
+ rubyforge_project: '[none]'
114
+ rubygems_version: 2.0.3
104
115
  signing_key:
105
- specification_version: 3
116
+ specification_version: 4
106
117
  summary: Routing filters wraps around the complex beast that the Rails routing system
107
118
  is, allowing for unseen flexibility and power in Rails URL recognition and generation
108
119
  test_files: []