routing-filter 0.4.0.1 → 0.5.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: 93c77279d99c3ef9273f30e201021a45c1d9fecc
4
- data.tar.gz: f6aea4562e3f3d7391e95ed7f2f144367923dbfa
3
+ metadata.gz: 155e4e4ff03c1905b4e940cd44a6882e44476251
4
+ data.tar.gz: 54c1d04f984a69ac8d6ca3cd68b8f02fe1c92730
5
5
  SHA512:
6
- metadata.gz: 74dda3bad3c4ce07c421b404dfc976e67bdeacecad3897b62ce7a8db706ca87189e0d88a71e90734aa40c93f96db5183e7a340ed4683154a051603f6c850ad37
7
- data.tar.gz: 4f2da211024088715d179c5275d113e3cacba82508f622984b6c1898a3c3f9ef6941cdfce9a4a067674ebefa30432b3cba36707f554c64869e492359ccdc66d5
6
+ metadata.gz: 293cb31a89bb6eb35013b2beac05cb4698ea072454bdf5afb95cf6b8817cc2855894e1967c20cfda8ca2c3991e5c3fdb324892a8961c89eb79f01879b2548c68
7
+ data.tar.gz: d37b6148b8e35ada00cc2b914f3a150abb7641cd9239fc28b49b553f5c884341fba7a74af0ae926881ee1b850a4c393fec82917656a2655b4064ab466ea72492
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.5.0
2
+
3
+ * Rails 4.2 only support
4
+
5
+ ## 0.4.0
6
+
7
+ * Rails 4 support
8
+
1
9
  ## 0.3.1
2
10
  * Filters support exclude option.
3
11
 
data/README.markdown CHANGED
@@ -19,48 +19,47 @@ implement custom ones. Maybe the most popular one is the Locale routing filter:
19
19
  * `Uuid` - prepends a uuid for authentication or other purposes (e.g. /d00fbbd1-82b6-4c1a-a57d-098d529d6854/products/1)
20
20
  * `Extension` - appends an extension (e.g. /products.html)
21
21
 
22
- Please note that Rails 3's routing system is much more powerful and flexible
23
- than Rails 2 was. There are many usecases that now can be covered with just
24
- Rails 3 default routing features that weren't doable in Rails 2. For an example
25
- of a quite complex and flexible route see this [gist by Andrew White](http://gist.github.com/653543)
26
22
 
27
23
  ## Requirements
28
24
 
29
- routing-filter currently only works with Rails. It should not be all too hard
25
+ Latest routing-filter (~> 0.5.0) currently only works with Rails 4.2. It should not be all too hard
30
26
  to get it working with plain Rack::Mount but I haven't had that usecase, yet.
31
27
 
28
+ For older Rails use `0-4-stable` branch.
29
+
32
30
  ## Installation
33
31
 
34
32
  Just install the Gem:
35
33
 
36
34
  $ gem install routing-filter
37
35
 
38
- The Gem should work out of the box for Rails 3 after specifying it in your
36
+ The Gem should work out of the box with Rails 4.2 after specifying it in your
39
37
  application's Gemfile.
40
38
 
41
- # Gemfile
42
- gem 'routing-filter'
43
-
44
- In order to use it with Rails 2.x you could specify it in your environment.rb
45
-
46
- # config/environment.rb
47
- gem 'routing-filter'
39
+ ```ruby
40
+ # Gemfile
41
+ gem 'routing-filter'
42
+ ```
48
43
 
49
44
  ## Usage
50
45
 
51
46
  Once the Gem has loaded you can setup the filters in your routes file like this:
52
47
 
53
- # in config/routes.rb
54
- Rails.application.routes.draw do
55
- filter :pagination, :uuid
56
- end
48
+ ```ruby
49
+ # in config/routes.rb
50
+ Rails.application.routes.draw do
51
+ filter :pagination, :uuid
52
+ end
53
+ ```
57
54
 
58
55
  Filters can also accept options:
59
56
 
60
- Rails.application.routes.draw do
61
- filter :extension, :exclude => %r(^admin/)
62
- filter :locale, :exclude => /^\/admin/
63
- end
57
+ ```ruby
58
+ Rails.application.routes.draw do
59
+ filter :extension, :exclude => %r(^admin/)
60
+ filter :locale, :exclude => /^\/admin/
61
+ end
62
+ ```
64
63
 
65
64
  ### Testing
66
65
 
@@ -71,23 +70,14 @@ gets executed for these testcases.
71
70
 
72
71
  To disable RoutingFilter in your test suite add the following to your test_helper.rb / spec_helper.rb:
73
72
 
74
- RoutingFilter.active = false
73
+ ```ruby
74
+ RoutingFilter.active = false
75
+ ```
75
76
 
76
77
  ## Running the tests
77
78
 
78
- To run the tests against different dependencies [appraisal](https://github.com/thoughtbot/appraisal) is used.
79
-
80
- Running the tests for all supported Rails versions:
81
-
82
79
  $ bundle install
83
- $ bundle exec rake all
84
-
85
- Running the tests for a single version, for example Rails 3.1:
86
-
87
- $ bundle install
88
- $ bundle exec rake appraisal:rails-3.1 test
89
-
90
- Valid appraisal targets include rails-2.3, rails-3.0, rails-3.1 and rails-3.2
80
+ $ bundle exec rake test
91
81
 
92
82
  ## Filter order
93
83
 
@@ -109,36 +99,40 @@ For example implementations have a look at the existing filters in
109
99
 
110
100
  The following would be a sceleton of an empty filter:
111
101
 
112
- module RoutingFilter
113
- class Awesomeness < Filter
114
- def around_recognize(path, env, &block)
115
- # Alter the path here before it gets recognized.
116
- # Make sure to yield (calls the next around filter if present and
117
- # eventually `recognize_path` on the routeset):
118
- yield.tap do |params|
119
- # You can additionally modify the params here before they get passed
120
- # to the controller.
121
- end
122
- end
123
-
124
- def around_generate(params, &block)
125
- # Alter arguments here before they are passed to `url_for`.
126
- # Make sure to yield (calls the next around filter if present and
127
- # eventually `url_for` on the controller):
128
- yield.tap do |result|
129
- # You can change the generated url_or_path here. Make sure to use
130
- # one of the "in-place" modifying String methods though (like sub!
131
- # and friends).
132
- end
133
- end
102
+ ```ruby
103
+ module RoutingFilter
104
+ class Awesomeness < Filter
105
+ def around_recognize(path, env, &block)
106
+ # Alter the path here before it gets recognized.
107
+ # Make sure to yield (calls the next around filter if present and
108
+ # eventually `recognize_path` on the routeset):
109
+ yield.tap do |params|
110
+ # You can additionally modify the params here before they get passed
111
+ # to the controller.
134
112
  end
135
113
  end
136
114
 
115
+ def around_generate(params, &block)
116
+ # Alter arguments here before they are passed to `url_for`.
117
+ # Make sure to yield (calls the next around filter if present and
118
+ # eventually `url_for` on the controller):
119
+ yield.tap do |result|
120
+ # You can change the generated url_or_path here. Make sure to use
121
+ # one of the "in-place" modifying String methods though (like sub!
122
+ # and friends).
123
+ end
124
+ end
125
+ end
126
+ end
127
+ ```
128
+
137
129
  You can specify the filter explicitely in your routes.rb:
138
130
 
139
- Rails.application.routes.draw do
140
- filter :awesomeness
141
- end
131
+ ```ruby
132
+ Rails.application.routes.draw do
133
+ filter :awesomeness
134
+ end
135
+ ```
142
136
 
143
137
  (I am not sure if it makes sense to provide more technical information than
144
138
  this because the usage of this plugin definitely requires some advanced
@@ -22,9 +22,13 @@ ActionDispatch::Routing::RouteSet.class_eval do
22
22
  names.each { |name| filters.unshift(RoutingFilter.build(name, options)) }
23
23
  end
24
24
 
25
- def generate_with_filtering(options, recall = {})
25
+ def generate_with_filtering(route_key, options, recall = {})
26
+ options = options.symbolize_keys
27
+
26
28
  # `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) })
29
+ filters.run(:around_generate, options, &lambda{
30
+ generate_without_filtering(route_key, options, recall).map(&:dup)
31
+ })
28
32
  end
29
33
  alias_method_chain :generate, :filtering
30
34
 
@@ -1,20 +1,13 @@
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
8
-
9
- journey::Routes.class_eval do
1
+ ActionDispatch::Journey::Routes.class_eval do
10
2
  def filters
11
3
  @filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
12
4
  end
13
5
  end
14
6
 
15
- journey::Router.class_eval do
16
- def find_routes_with_filtering env
17
- path, filter_parameters = env['PATH_INFO'], {}
7
+ ActionDispatch::Journey::Router.class_eval do
8
+ def find_routes_with_filtering(env)
9
+ path = env.is_a?(Hash) ? env['PATH_INFO'] : env.path_info
10
+ filter_parameters = {}
18
11
  original_path = path.dup
19
12
 
20
13
  @routes.filters.run(:around_recognize, path, env) do
@@ -1,3 +1,3 @@
1
1
  module RoutingFilter
2
- VERSION = '0.4.0.1'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -24,4 +24,4 @@ module RoutingFilter
24
24
  end
25
25
  end
26
26
 
27
- require "routing_filter/adapters/rails_#{ActionPack::VERSION::MAJOR}"
27
+ require "routing_filter/adapters/rails"
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routing-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-17 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.2'
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
26
  version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: appraisal
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
33
+ version: '4.2'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '4.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: i18n
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.6.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.2'
69
97
  description: Routing filters wraps around the complex beast that the Rails routing
70
98
  system is, allowing for unseen flexibility and power in Rails URL recognition and
71
99
  generation.
@@ -80,9 +108,7 @@ files:
80
108
  - lib/routing-filter.rb
81
109
  - lib/routing/filter.rb
82
110
  - lib/routing_filter.rb
83
- - lib/routing_filter/adapters/rails_2.rb
84
- - lib/routing_filter/adapters/rails_3.rb
85
- - lib/routing_filter/adapters/rails_4.rb
111
+ - lib/routing_filter/adapters/rails.rb
86
112
  - lib/routing_filter/adapters/routers/journey.rb
87
113
  - lib/routing_filter/adapters/routers/rack_mount.rb
88
114
  - lib/routing_filter/chain.rb
@@ -1,69 +0,0 @@
1
- require 'action_controller'
2
-
3
- # allows to install a filter to the route set by calling: map.filter 'locale'
4
- ActionController::Routing::RouteSet::Mapper.class_eval do
5
- def filter(*args)
6
- @set.add_filters(*args)
7
- end
8
- end
9
-
10
- # same here for the optimized url generation in named routes
11
- ActionController::Routing::RouteSet::NamedRouteCollection.class_eval do
12
- # gosh. monkey engineering optimization code
13
- def generate_optimisation_block_with_filtering(*args)
14
- code = generate_optimisation_block_without_filtering(*args)
15
- if match = code.match(%r(^return (.*) if (.*)))
16
- # returned string must not contain newlines, or we'll spill out of inline code comments in
17
- # ActionController::Routing::RouteSet::NamedRouteCollection#define_url_helper
18
- "#{match[1]}.tap { |result|" +
19
- " ActionController::Routing::Routes.filters.run(:around_generate, *args, &lambda{ result }) " +
20
- "} if #{match[2]}"
21
- end
22
- end
23
- alias_method_chain :generate_optimisation_block, :filtering
24
- end
25
-
26
- ActionController::Routing::RouteSet.class_eval do
27
- attr_writer :filters
28
-
29
- def filters
30
- @filters ||= RoutingFilter::Chain.new
31
- end
32
-
33
- def add_filters(*names)
34
- options = names.extract_options!
35
- names.each { |name| filters.unshift(RoutingFilter.build(name, options)) }
36
- end
37
-
38
- def recognize_path_with_filtering(path, env = {})
39
- path = ::URI.unescape(path.dup) # string is frozen due to memoize
40
- filters.run(:around_recognize, path, env, &lambda{ recognize_path_without_filtering(path, env) })
41
- end
42
- alias_method_chain :recognize_path, :filtering
43
-
44
- def generate_with_filtering(*args)
45
- filters.run(:around_generate, args.first, &lambda{ generate_without_filtering(*args) })
46
- end
47
- alias_method_chain :generate, :filtering
48
-
49
- def clear_with_filtering!
50
- @filters.clear if @filters
51
- clear_without_filtering!
52
- end
53
- alias_method_chain :clear!, :filtering
54
-
55
- # add some useful information to the request environment
56
- # right, this is from jamis buck's excellent article about routes internals
57
- # http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2
58
- # TODO move this ... where?
59
- alias_method :extract_request_environment_without_host, :extract_request_environment unless method_defined? :extract_request_environment_without_host
60
- def extract_request_environment(request)
61
- extract_request_environment_without_host(request).tap do |env|
62
- env.merge! :host => request.host,
63
- :port => request.port,
64
- :host_with_port => request.host_with_port,
65
- :domain => request.domain,
66
- :subdomain => request.subdomains.first
67
- end
68
- end
69
- end
@@ -1,47 +0,0 @@
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 recognize_path_with_filtering(path, env = {})
26
- # @set.filters.run(:around_recognize, path.dup, env, &lambda{ recognize_path_without_filtering(path.dup, env) })
27
- # end
28
- # alias_method_chain :recognize_path, :filtering
29
-
30
- def generate_with_filtering(options, recall = {}, extras = false)
31
- filters.run(:around_generate, options, &lambda{ generate_without_filtering(options, recall, extras) })
32
- end
33
- alias_method_chain :generate, :filtering
34
-
35
- def clear_with_filtering!
36
- filters.clear if filters
37
- clear_without_filtering!
38
- end
39
- alias_method_chain :clear!, :filtering
40
- end
41
-
42
- case ActionPack::VERSION::MINOR
43
- when 2
44
- require 'routing_filter/adapters/routers/journey'
45
- when 0,1
46
- require 'routing_filter/adapters/routers/rack_mount'
47
- end