Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Now working on Rails 4

  • Loading branch information...
commit f18d23cf83760d24c9e63e95a83df3b1baf95c18 1 parent db2769e
@tricknotes tricknotes authored
View
4 Appraisals
@@ -14,3 +14,7 @@ end
appraise 'rails-3.2' do
gem 'rails', '~> 3.2.0.rc1'
end
+
+appraise 'rails-4.0' do
+ gem 'rails', '~> 4.0.0.beta1'
+end
View
7 gemfiles/rails-4.0.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source :rubygems
+
+gem "rails", "~> 4.0.0.beta1"
+
+gemspec :path=>"../"
View
44 lib/routing_filter/adapters/rails_4.rb
@@ -0,0 +1,44 @@
+require 'action_dispatch'
+require 'active_support/core_ext/module/aliasing'
+require 'active_support/core_ext/hash/reverse_merge'
+
+mappers = [ActionDispatch::Routing::Mapper]
+mappers << ActionDispatch::Routing::DeprecatedMapper if defined?(ActionDispatch::Routing::DeprecatedMapper)
+mappers.each do |mapper|
+ mapper.class_eval do
+ def filter(*args)
+ @set.add_filters(*args)
+ end
+ end
+end
+
+ActionDispatch::Routing::RouteSet.class_eval do
+ def filters
+ @set.filters if @set
+ end
+
+ def add_filters(*names)
+ options = names.extract_options!
+ names.each { |name| filters.unshift(RoutingFilter.build(name, options)) }
+ end
+
+ def generate_with_filtering(options, recall = {})
+ # `around_generate` is destructive method and it breaks url. To avoid this, `dup` is required.
+ filters.run(:around_generate, options, &lambda{ generate_without_filtering(options, recall).map(&:dup) })
+ end
+ alias_method_chain :generate, :filtering
+
+ def clear_with_filtering!
+ filters.clear if filters
+ clear_without_filtering!
+ end
+ alias_method_chain :clear!, :filtering
+end
+
+ActionDispatch::Journey::Routes.class_eval do
+ def filters
+ @filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
+ end
+end
+
+require 'routing_filter/adapters/routers/journey'
View
13 lib/routing_filter/adapters/routers/journey.rb
@@ -1,13 +1,18 @@
-require 'journey/routes'
-require 'journey/router'
+if defined?(ActionDispatch::Journey) # rails 4
+ journey = ActionDispatch::Journey
+else # rails 3.2
+ require 'journey/routes'
+ require 'journey/router'
+ journey = Journey
+end
-Journey::Routes.class_eval do
+journey::Routes.class_eval do
def filters
@filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
end
end
-Journey::Router.class_eval do
+journey::Router.class_eval do
def find_routes_with_filtering env
path, filter_parameters = env['PATH_INFO'], {}
original_path = path.dup
View
1  test/test_adapters/rails_4.rb
@@ -0,0 +1 @@
+require 'test_adapters/rails_3'
Please sign in to comment.
Something went wrong with that request. Please try again.