rework part of configure mechanism
authorLunar <lunar@anargeek.net>
Sun, 29 Jan 2012 17:57:42 +0000 (18:57 +0100)
committerLunar <lunar@anargeek.net>
Tue, 14 Feb 2012 17:38:58 +0000 (18:38 +0100)
We can now use `app.set :authentication_method, ...` which is useful for
tests.

lib/coquelicot/configure.rb

index ca5ed5d..c687ece 100644 (file)
@@ -1,27 +1,27 @@
 module Coquelicot::Configure
 module Coquelicot::Configure
-  
   def self.included(c)
     c.extend ClassMethods
     c.configure
   end
   def self.included(c)
     c.extend ClassMethods
     c.configure
   end
-  
+
   module ClassMethods
     def configure
   module ClassMethods
     def configure
-      user_settings = File.exists?(settings_path) ? load_user_settings : {}
-      default_settings.delete('authentication_method') if user_settings['authentication_method']
-      merged_settings = default_settings.merge(user_settings)
-      if (authm=merged_settings.delete('authentication_method'))
-        authentication_method authm.delete('name'), authm
-      end
-      merged_settings.each{|k,v| set k,v }
+      user_settings = load_user_settings if File.exists?(settings_path)
+      merged_settings = default_settings.merge(user_settings || {})
+      merged_settings.each { |k,v| set k,v }
     end
     end
-    private
-    def authentication_method(method,options={})
+
+    def authentication_method=(options)
+      method = options.delete('name') || options.delete(:name)
+      method = method.to_s if method.is_a? Symbol
       require "coquelicot/auth/#{method}"
       set :authenticator, Coquelicot::Auth.
          const_get("#{method.to_s.capitalize}Authenticator").new(self)
       options.each{|k,v| set k,v }
     end
       require "coquelicot/auth/#{method}"
       set :authenticator, Coquelicot::Auth.
          const_get("#{method.to_s.capitalize}Authenticator").new(self)
       options.each{|k,v| set k,v }
     end
+
+  private
+
     def default_settings
       {
         'default_expire' => 60,
     def default_settings
       {
         'default_expire' => 60,
@@ -34,15 +34,15 @@ module Coquelicot::Configure
         'depot_path' => Proc.new { File.join(root, 'files') },
         'authentication_method' => {
           'name' => 'simplepass',
         'depot_path' => Proc.new { File.join(root, 'files') },
         'authentication_method' => {
           'name' => 'simplepass',
-          'upload_password' => 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'          
+          'upload_password' => 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'
         },
       }
     end
         },
       }
     end
-    
+
     def settings_path
       @settings_path ||= File.join(File.dirname(__FILE__),'..','..','conf','settings.yml')
     end
     def settings_path
       @settings_path ||= File.join(File.dirname(__FILE__),'..','..','conf','settings.yml')
     end
-    
+
     def load_user_settings
       YAML.load(File.read(settings_path))
     end
     def load_user_settings
       YAML.load(File.read(settings_path))
     end