Permalink
Browse files

Added db_setup? method to avoid errors during rake tasks where the db…

… might not be set up. Ex: migrations
  • Loading branch information...
binarylogic committed Jun 3, 2009
1 parent bab7994 commit 6e901ba009351167bd8cf45505bc930daed81008
Showing with 13 additions and 6 deletions.
  1. +13 −6 lib/authlogic/acts_as_authentic/base.rb
@@ -25,11 +25,7 @@ module Config
# See the various sub modules for the configuration they provide.
def acts_as_authentic(unsupported_options = nil, &block)
# Stop all configuration if the DB is not set up
- begin
- column_names
- rescue Exception
- return
- end
+ return if !db_setup?
raise ArgumentError.new("You are using the old v1.X.X configuration method for Authlogic. Instead of " +
"passing a hash of configuration options to acts_as_authentic, pass a block: acts_as_authentic { |c| c.my_option = my_value }") if !unsupported_options.nil?
@@ -68,6 +64,15 @@ def acts_as_authentic_modules
inheritable_attributes.include?(key) ? read_inheritable_attribute(key) : []
end
+ def db_setup?
+ begin
+ column_names
+ true
+ rescue Exception
+ false
+ end
+ end
+
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
@@ -77,7 +82,9 @@ def rw_config(key, value, default_value = nil, read_value = nil)
end
def first_column_to_exist(*columns_to_check)
- columns_to_check.each { |column_name| return column_name.to_sym if column_names.include?(column_name.to_s) }
+ if db_setup?
+ columns_to_check.each { |column_name| return column_name.to_sym if column_names.include?(column_name.to_s) }
+ end
columns_to_check.first && columns_to_check.first.to_sym
end
end

0 comments on commit 6e901ba

Please sign in to comment.