Skip to content

Instantly share code, notes, and snippets.

@rust
Created July 16, 2010 02:12
Show Gist options
  • Save rust/477821 to your computer and use it in GitHub Desktop.
Save rust/477821 to your computer and use it in GitHub Desktop.
diff --git a/lib/jpmobile/rack.rb b/lib/jpmobile/rack.rb
index c4c6a66..09187bc 100644
--- a/lib/jpmobile/rack.rb
+++ b/lib/jpmobile/rack.rb
@@ -7,13 +7,35 @@ module Jpmobile
autoload :ParamsFilter, 'jpmobile/rack/params_filter.rb'
autoload :Filter, 'jpmobile/rack/filter.rb'
autoload :Config, 'jpmobile/rack/config.rb'
+
+ module_function
+ def mount_middlewares
+ # 漢字コード・絵文字フィルター
+ ::Rails::Application.config.middleware.insert_before('ActionDispatch::ParamsParser', Jpmobile::Rack::ParamsFilter)
+ ::Rails::Application.config.middleware.insert_before('ActionDispatch::ParamsParser', Jpmobile::Rack::Filter)
+ end
+ end
+
+ class Configuration
+ def mobile_filter
+ ::Jpmobile::Rack.mount_middlewares
+ end
end
end
if Object.const_defined?(:Rails)
- Rails::Application.config.middleware.insert_before('ActionDispatch::ParamsParser', Jpmobile::Rack::MobileCarrier)
- Rails::Application.config.middleware.insert_before('ActionDispatch::ParamsParser', Jpmobile::Rack::ParamsFilter)
- Rails::Application.config.middleware.insert_before('ActionDispatch::ParamsParser', Jpmobile::Rack::Filter)
+ # MobileCarrierのみデフォルトで有効
+ ::Rails::Application.config.middleware.insert_before('ActionDispatch::ParamsParser', Jpmobile::Rack::MobileCarrier)
+
+ module Rails
+ class Application
+ class Configuration
+ def jpmobile
+ @jpmobile ||= ::Jpmobile::Configuration.new
+ end
+ end
+ end
+ end
end
require 'rack/utils'
diff --git a/test/rails/overrides/config/initializers/jpmobile_generator.rb b/test/rails/overrides/config/initializers/jpmobile_generator.rb
new file mode 100644
index 0000000..bc871c6
--- /dev/null
+++ b/test/rails/overrides/config/initializers/jpmobile_generator.rb
@@ -0,0 +1 @@
+Rails.application.config.jpmobile.mobile_filter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment