Skip to content

Commit

Permalink
rails 3.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasWurm committed May 8, 2011
1 parent 98a8dd3 commit 7b114e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
26 changes: 14 additions & 12 deletions lib/authlogic/acts_as_authentic/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module ActsAsAuthentic
module Base
def self.included(klass)
klass.class_eval do
class_attribute :acts_as_authentic_modules, :acts_as_authentic_config
self.acts_as_authentic_modules ||= []
self.acts_as_authentic_config ||= {}
extend Config
end
end
Expand Down Expand Up @@ -41,29 +44,25 @@ def acts_as_authentic(unsupported_options = nil, &block)
#
# That being said, this is your tool for extending Authlogic and "hooking" into the acts_as_authentic call.
def add_acts_as_authentic_module(mod, action = :append)
modules = acts_as_authentic_modules
modules = acts_as_authentic_modules.clone
case action
when :append
modules << mod
when :prepend
modules = [mod] + modules
end
modules.uniq!
write_inheritable_attribute(:acts_as_authentic_modules, modules)
self.acts_as_authentic_modules = modules
end

# This is the same as add_acts_as_authentic_module, except that it removes the module from the list.
def remove_acts_as_authentic_module(mod)
acts_as_authentic_modules.delete(mod)
acts_as_authentic_modules
modules = acts_as_authentic_modules.clone
modules.delete(mod)
self.acts_as_authentic_modules = modules
end

private
def acts_as_authentic_modules
key = :acts_as_authentic_modules
inheritable_attributes.include?(key) ? read_inheritable_attribute(key) : []
end

def db_setup?
begin
column_names
Expand All @@ -75,9 +74,12 @@ def db_setup?

def rw_config(key, value, default_value = nil, read_value = nil)
if value == read_value
inheritable_attributes.include?(key) ? read_inheritable_attribute(key) : default_value
acts_as_authentic_config.include?(key) ? acts_as_authentic_config[key] : default_value
else
write_inheritable_attribute(key, value)
config = acts_as_authentic_config.clone
config[key] = value
self.acts_as_authentic_config = config
value
end
end

Expand Down
12 changes: 9 additions & 3 deletions lib/authlogic/session/foundation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module Session
module Foundation
def self.included(klass)
klass.class_eval do
class_attribute :acts_as_authentic_config
self.acts_as_authentic_config ||= {}

extend ClassMethods
include InstanceMethods
end
Expand All @@ -15,10 +18,13 @@ module ClassMethods
private
def rw_config(key, value, default_value = nil, read_value = nil)
if value == read_value
return read_inheritable_attribute(key) if inheritable_attributes.include?(key)
write_inheritable_attribute(key, default_value)
return acts_as_authentic_config[key] if acts_as_authentic_config.include?(key)
rw_config(key, default_value)
else
write_inheritable_attribute(key, value)
config = acts_as_authentic_config.clone
config[key] = value
self.acts_as_authentic_config = config
value
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#ActiveRecord::Schema.verbose = false
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
logger = Logger.new(STDOUT)
logger.level= Logger::FATAL
ActiveRecord::Base.logger = logger

ActiveRecord::Base.configurations = true
ActiveRecord::Schema.define(:version => 1) do
Expand Down

0 comments on commit 7b114e7

Please sign in to comment.