aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-13 08:31:32 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-13 08:31:32 +0000
commitebb7bd78351b7975f28fdcbadbbf0fe4804be2f2 (patch)
tree7be64a13212fce30d2ed351ed25d6ef3aeae9e59
parent48018bf4b5e5a2e173b4744abddc3e8cb590b4df (diff)
downloadrails-ebb7bd78351b7975f28fdcbadbbf0fe4804be2f2.tar.gz
rails-ebb7bd78351b7975f28fdcbadbbf0fe4804be2f2.tar.bz2
rails-ebb7bd78351b7975f28fdcbadbbf0fe4804be2f2.zip
Added easy assignment of fragment cache store through use of symbols for included stores (old way still works too)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2230 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG9
-rwxr-xr-xactionpack/lib/action_controller.rb2
-rw-r--r--actionpack/lib/action_controller/caching.rb37
-rw-r--r--actionpack/lib/action_controller/cgi_process.rb5
-rw-r--r--actionpack/lib/action_controller/session.rb14
-rw-r--r--actionpack/lib/action_controller/session_management.rb21
-rw-r--r--actionpack/test/controller/fragment_store_setting_test.rb45
-rw-r--r--actionpack/test/controller/session_management_test.rb10
8 files changed, 105 insertions, 38 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index a3cd28bf4b..4302a2c085 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,14 @@
*SVN*
+* Added easy assignment of fragment cache store through use of symbols for included stores (old way still works too)
+
+ Before:
+ ActionController::Base.fragment_cache_store =
+ ActionController::Base::Caching::Fragments::FileStore.new("/path/to/cache/directory")
+
+ After:
+ ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory"
+
* Added ActionController::Base.session_store=, session_store, and session_options to make it easier to tweak the session options (instead of going straight to ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
* Added TextHelper#cycle to cycle over an array of values on each hit (useful for alternating row colors etc) #2154 [dave-ml@dribin.org]
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index 0eaf630bbe..cdc9102062 100755
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -38,7 +38,6 @@ require 'action_controller/benchmarking'
require 'action_controller/filters'
require 'action_controller/layout'
require 'action_controller/flash'
-require 'action_controller/session'
require 'action_controller/dependencies'
require 'action_controller/pagination'
require 'action_controller/scaffolding'
@@ -67,7 +66,6 @@ ActionController::Base.class_eval do
include ActionController::Scaffolding
include ActionController::Helpers
include ActionController::Cookies
- include ActionController::Session
include ActionController::Caching
include ActionController::Components
include ActionController::Verification
diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb
index 095fb7f2f2..88529d8008 100644
--- a/actionpack/lib/action_controller/caching.rb
+++ b/actionpack/lib/action_controller/caching.rb
@@ -240,23 +240,28 @@ module ActionController #:nodoc:
#
# Configuration examples (MemoryStore is the default):
#
- # ActionController::Base.fragment_cache_store =
- # ActionController::Caching::Fragments::MemoryStore.new
- #
- # ActionController::Base.fragment_cache_store =
- # ActionController::Caching::Fragments::FileStore.new("/path/to/cache/directory")
- #
- # ActionController::Base.fragment_cache_store =
- # ActionController::Caching::Fragments::DRbStore.new("druby://localhost:9192")
- #
- # ActionController::Base.fragment_cache_store =
- # ActionController::Caching::Fragments::MemCacheStore.new("localhost")
+ # ActionController::Base.fragment_cache_store = :memory_store
+ # ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory"
+ # ActionController::Base.fragment_cache_store = :drb_store, "druby://localhost:9192"
+ # ActionController::Base.fragment_cache_store = :mem_cache_store, "localhost"
+ # ActionController::Base.fragment_cache_store = MyOwnStore.new("parameter")
module Fragments
def self.append_features(base) #:nodoc:
super
base.class_eval do
@@fragment_cache_store = MemoryStore.new
- cattr_accessor :fragment_cache_store
+ cattr_reader :fragment_cache_store
+
+ def self.fragment_cache_store=(store_option)
+ store, *parameters = *([ store_option ].flatten)
+ @@fragment_cache_store = if store.is_a?(Symbol)
+ store_class_name = (store == :drb_store ? "DRbStore" : store.to_s.camelize)
+ store_class = ActionController::Caching::Fragments.const_get(store_class_name)
+ parameters.empty? ? store.new : store_class.new(*parameters)
+ else
+ store
+ end
+ end
end
end
@@ -349,18 +354,26 @@ module ActionController #:nodoc:
end
class DRbStore < MemoryStore #:nodoc:
+ attr_reader :address
+
def initialize(address = 'druby://localhost:9192')
+ @address = address
@data, @mutex = DRbObject.new(nil, address), Mutex.new
end
end
class MemCacheStore < MemoryStore #:nodoc:
+ attr_reader :address
+
def initialize(address = 'localhost')
+ @address = address
@data, @mutex = MemCache.new(address), Mutex.new
end
end
class FileStore #:nodoc:
+ attr_reader :cache_path
+
def initialize(cache_path)
@cache_path = cache_path
end
diff --git a/actionpack/lib/action_controller/cgi_process.rb b/actionpack/lib/action_controller/cgi_process.rb
index e9e539cfdc..d59de771c9 100644
--- a/actionpack/lib/action_controller/cgi_process.rb
+++ b/actionpack/lib/action_controller/cgi_process.rb
@@ -1,11 +1,6 @@
require 'action_controller/cgi_ext/cgi_ext'
require 'action_controller/cgi_ext/cookie_performance_fix'
require 'action_controller/cgi_ext/raw_post_data_fix'
-require 'action_controller/session/drb_store'
-require 'action_controller/session/mem_cache_store'
-if Object.const_defined?(:ActiveRecord)
- require 'action_controller/session/active_record_store'
-end
module ActionController #:nodoc:
class Base
diff --git a/actionpack/lib/action_controller/session.rb b/actionpack/lib/action_controller/session.rb
deleted file mode 100644
index f3c3f87499..0000000000
--- a/actionpack/lib/action_controller/session.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module ActionController #:nodoc:
- module Session #:nodoc:
- def self.append_features(base) #:nodoc:
- super #:nodoc:
- base.after_filter(:clear_persistant_model_associations)
- end
-
- private
- def clear_persistant_model_associations #:doc:
- session = @session.instance_variable_get("@data")
- session.each { |key, obj| obj.clear_association_cache if obj.respond_to?(:clear_association_cache) } if session
- end
- end
-end \ No newline at end of file
diff --git a/actionpack/lib/action_controller/session_management.rb b/actionpack/lib/action_controller/session_management.rb
index 193910d470..b0a457932d 100644
--- a/actionpack/lib/action_controller/session_management.rb
+++ b/actionpack/lib/action_controller/session_management.rb
@@ -1,12 +1,17 @@
+require 'action_controller/session/drb_store'
+require 'action_controller/session/mem_cache_store'
+if Object.const_defined?(:ActiveRecord)
+ require 'action_controller/session/active_record_store'
+end
+
module ActionController #:nodoc:
module SessionManagement #:nodoc:
def self.append_features(base)
super
base.extend(ClassMethods)
- base.class_eval do
- alias_method :process_without_session_management_support, :process
- alias_method :process, :process_with_session_management_support
- end
+ base.send(:alias_method, :process_without_session_management_support, :process)
+ base.send(:alias_method, :process, :process_with_session_management_support)
+ base.after_filter(:clear_persistant_model_associations)
end
module ClassMethods
@@ -15,7 +20,7 @@ module ActionController #:nodoc:
# :mem_cache_store, or :memory_store) or use your own class.
def session_store=(store)
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager] =
- store.is_a?(Symbol) ? CGI::Session.const_get(store.to_s.camelize) : store
+ store.is_a?(Symbol) ? CGI::Session.const_get(store == :drb_store ? "DRbStore" : store.to_s.camelize) : store
end
# Returns the session store class currently used.
@@ -100,5 +105,11 @@ module ActionController #:nodoc:
request.session_options = self.class.session_options_for(request, action)
process_without_session_management_support(request, response, method, *arguments)
end
+
+ private
+ def clear_persistant_model_associations #:doc:
+ session = @session.instance_variable_get("@data")
+ session.each { |key, obj| obj.clear_association_cache if obj.respond_to?(:clear_association_cache) } if session
+ end
end
end
diff --git a/actionpack/test/controller/fragment_store_setting_test.rb b/actionpack/test/controller/fragment_store_setting_test.rb
new file mode 100644
index 0000000000..fde70965f6
--- /dev/null
+++ b/actionpack/test/controller/fragment_store_setting_test.rb
@@ -0,0 +1,45 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+MemCache = Struct.new(:MemCache, :address)
+
+class FragmentCacheStoreSettingTest < Test::Unit::TestCase
+ def teardown
+ ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::MemoryStore.new
+ end
+
+ def test_file_fragment_cache_store
+ ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory"
+ assert_kind_of(
+ ActionController::Caching::Fragments::FileStore,
+ ActionController::Base.fragment_cache_store
+ )
+ assert_equal "/path/to/cache/directory", ActionController::Base.fragment_cache_store.cache_path
+ end
+
+ def test_drb_fragment_cache_store
+ ActionController::Base.fragment_cache_store = :drb_store, "druby://localhost:9192"
+ assert_kind_of(
+ ActionController::Caching::Fragments::DRbStore,
+ ActionController::Base.fragment_cache_store
+ )
+ assert_equal "druby://localhost:9192", ActionController::Base.fragment_cache_store.address
+ end
+
+ def test_mem_cache_fragment_cache_store
+ ActionController::Base.fragment_cache_store = :mem_cache_store, "localhost"
+ assert_kind_of(
+ ActionController::Caching::Fragments::MemCacheStore,
+ ActionController::Base.fragment_cache_store
+ )
+ assert_equal "localhost", ActionController::Base.fragment_cache_store.address
+ end
+
+ def test_object_assigned_fragment_cache_store
+ ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::FileStore.new("/path/to/cache/directory")
+ assert_kind_of(
+ ActionController::Caching::Fragments::FileStore,
+ ActionController::Base.fragment_cache_store
+ )
+ assert_equal "/path/to/cache/directory", ActionController::Base.fragment_cache_store.cache_path
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/controller/session_management_test.rb b/actionpack/test/controller/session_management_test.rb
index 84cbd28387..c611cb8af5 100644
--- a/actionpack/test/controller/session_management_test.rb
+++ b/actionpack/test/controller/session_management_test.rb
@@ -81,4 +81,14 @@ class SessionManagementTest < Test::Unit::TestCase
get :conditional, :ws => "ws"
assert_equal false, @request.session_options
end
+
+ def test_session_store_setting
+ ActionController::Base.session_store = :drb_store
+ assert_equal CGI::Session::DRbStore, ActionController::Base.session_store
+
+ if Object.const_defined?(:ActiveRecord)
+ ActionController::Base.session_store = :active_record_store
+ assert_equal CGI::Session::ActiveRecordStore, ActionController::Base.session_store
+ end
+ end
end