<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>install.rb</filename>
    </added>
    <added>
      <filename>lib/config.rb</filename>
    </added>
    <added>
      <filename>lib/config_iterator.rb</filename>
    </added>
    <added>
      <filename>lib/exceptions.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -3,4 +3,45 @@ SugarfreeConfig
 
 Configuration handling the easy way.
 
+#
+# SugarFree config allows easy access to the config values.
+# 
+# Config must be stored in &quot;#{RAILS_ROOT}/config/config.yml&quot; and must have
+# at least a section for each RAILS_ENV
+# 
+# Configuration can be accessed like this
+# 
+#   app_config.a.b.c #=&gt; 'value'
+#   
+# which will expect a config file like (given development env)
+# 
+#   development:
+#     a:
+#       b:
+#         c: 'value'
+#
+# otherwise an ConfigKeyException will be issued
+#
+# The config object is accessible at any class or object of the application.
+# Configuration is accessed through a ConfigIterator that (as its name says) is
+# and iterator and cannot be reused. However there is a workaround to allow the
+# repeated use of scoped iterators.
+#  
+#   # This doesn't work
+#   var a_config = app_config.a
+#   a_config.b.c #=&gt; 'value'
+#   a_config.b.c #=&gt; Ups!!! trie to grab config.a.b.c.b.c
+# 
+#   # Workaround
+#   var a_config = app_config.a
+#   a_config.dup.b.c #=&gt; 'value'
+#   a_config.dup.b.c #=&gt; 'value'
+#
+
+# See SugarfreeConfig for module configuration
+
+SUGARFREE_CONFIG_ACCESSOR = 'app_config'
+SUGARFREE_CONFIG_INSTANCE_CACHING = false
+
+
 Copyright (c) 2008 [Trabe Soluciones, S.L.], released under the MIT license</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,9 @@
-# Hook the Sugarfree config modules to Rails base classes
-
 require 'sugarfree_config'
+require 'exceptions'
+require 'config'
+require 'config_iterator'
 
+# Hook the Sugarfree Config  to the application objects
 ::Object.class_eval do
   include SugarfreeConfig
 end</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,197 +1,86 @@
 #
-# SugarFree config allows easy access to the config values.
-# 
-# Config must be stored in &quot;#{RAILS_ROOT}/config/config.yml&quot; and must have
-# at least a section for each RAILS_ENV
-# 
-# Configuration can be accessed like this
-# 
-#   app_config.a.b.c #=&gt; 'value'
-#   
-# which will expect a config file like (given development env)
-# 
-#   development:
-#     a:
-#       b:
-#         c: 'value'
-#
-# otherwise an ConfigKeyException will be issued
-#
-# The config object is accessible at any class or object of the application.
-# Configuration is accessed through a ConfigIterator that (as its name says) is
-# and iterator and cannot be reused. However there is a workaround to allow the
-# repeated use of scoped iterators.
-#  
-#   # This doesn't work
-#   var a_config = app_config.a
-#   a_config.b.c #=&gt; 'value'
-#   a_config.b.c #=&gt; Ups!!! trie to grab config.a.b.c.b.c
-# 
-#   # Workaround
-#   var a_config = app_config.a
-#   a_config.dup.b.c #=&gt; 'value'
-#   a_config.dup.b.c #=&gt; 'value'
+# SugarfreeConfig module
 #
 module SugarfreeConfig
 
   #
-  # Exception raised by the module on unexpected behaviors
-  #
-  class ConfigException &lt; Exception
-  end
-  
-  #
-  # Exception raised by the COnfig Iterator when akey is not found
-  #
-  class ConfigKeyException &lt; ConfigException
-    
-    #
-    # Config key path (as a key collection) that failed
-    #
-    attr_accessor :key_path_elements
-    
-    #
-    # Create a new exception with the not found key paths (+key_path_elements+
-    # Array)
-    #
-    def initialize(key_path_elements)
-      self.key_path_elements = [*key_path_elements].map(&amp;:to_s)
-      super(&quot;Cannot find key #{self.key_path_elements.join('.')}&quot;)
-    end
-  end
-    
-  #
-  # Config base object. Caches the configuration in memory an acts as a factory
-  # for the ConfigIterators needed to get config values
-  #
-  class Config
-    
-    #
-    # Conifg file is expected at &quot;#{RAILS_ROOT}/config/config.yml&quot;
-    #    
-    DEFAULT_CONFIG_FILE = File.join(RAILS_ROOT, 'config', 'config.yml')    
-    
-    #
-    # Accessor to grab the cached config values
-    #
-    cattr_accessor :config
-        
-    #
-    # Creates a new config object and load the config file into memory
-    #
-    def initialize(force_reload = false) 
-      @@config = fetch_config unless @@config &amp;&amp; !force_reload     
-    end
+  # Module configuration storage. Defines the default plugin configuration
+  # values, allows easy access and overriding.
+  # 
+  # Configurable parameters: 
+  #  TODO: Comment code Defaults and meaning
+  # 
+  class ModuleConfig
 
-    #
-    # Returns all the config as a big hash
-    #
-    def to_hash
-      @@config
-    end
-    
-    #
-    # Here is the magic. The first request to config returns a new 
-    # ConfigIterator that will handle the first +symbol+
-    #
-    def method_missing(symbol, *args)
-      ConfigIterator.new(@@config, symbol).next
-    end
-     
-    protected
+    attr_reader :accessor
+    attr_reader :instance_caching
     
-      #
-      # Fetch the config from the file
-      #
-      def fetch_config
-        if Object.const_defined?('RAILS_DEFAULT_LOGGER') &amp;&amp;
-          RAILS_DEFAULT_LOGGER.debug?          
-          RAILS_DEFAULT_LOGGER.debug &quot;Load #{DEFAULT_CONFIG_FILE}::#{RAILS_ENV}&quot;
-        end
-        HashWithIndifferentAccess.new(
-          YAML::load(File.new(DEFAULT_CONFIG_FILE))[RAILS_ENV])        
-      end
-    
-  end
+    attr_accessor :source
+    attr_accessor :reload_on_development
+    attr_accessor :logger
 
-  #
-  # Config Iterator. Given a configuration hash it can navigate trough the
-  # values using method calls that will be translated into hash keys and 
-  # indexed
-  #
-  class ConfigIterator
-    
-    #
-    # Create a new iterator with a given +configuration+ and the first 
-    # element of the path to be iterated (+first_path_element+)
     #
-    def initialize(configuration, first_path_element)
-      @scoped_config = configuration
-      @path_elements = [first_path_element]
-    end
-    
+    # Sets the default values
     #
-    # Returns the current scope as a hash. Usefull to get a Big hash of config
-    # that will be used later.
-    #
-    def to_hash      
-      @scoped_config
+    def initialize
+      @accessor = SUGARFREE_CONFIG_ACCESSOR || 'config'
+      @instance_caching = defined?(SUGARFREE_CONFIG_INSTANCE_CACHING) ?
+        SUGARFREE_CONFIG_INSTANCE_CACHING : true
+
+      @source = File.join(RAILS_ROOT, 'config', 'config.yml')
+      @reload_on_development = true
+      @logger = RAILS_DEFAULT_LOGGER            
     end
-    
+
     #
-    # Iterate to the next element in the path
-    # 
-    # Algorithm: 
-    # 1. Get the last element of the key path
-    # 2. Try to find it in the scoped config.
-    # 3. If not present raise an error
-    # 4. If present and is a hash we are not in a config leaf, so the scoped
-    #    config is reset to this new value and self is returned
-    # 5. If present and is a value then return the value
+    # Override some default config values given a hash of key, value +overrides+ 
     #
-    def next      
-      if (value = @scoped_config[@path_elements.last]).nil?
-        raise ConfigKeyException.new(@path_elements)
-      elsif value.is_a?(Hash)
-        @scoped_config = value
-        self
-      else
-        value
-      end
+    def override_with(overrides)
+      overrides.each { |k,v| self.send(&quot;#{k}=&quot;,v) if respond_to? &quot;#{k}=&quot; }
     end
+      
+    def reload_on_development
+      @reload_on_development &amp;&amp; RAILS_ENV != &quot;production&quot;
+    end    
     
-    #
-    # Here is the magic. When an unknown symbol is passed this symbol is set
-    # as the last path element of this iteration, and the iterator is then 
-    # forced to make that movement
-    #
     def method_missing(symbol, *args)
-      @path_elements &lt;&lt; symbol
-      self.next
+      symbol.to_s =~ /^(.+)\?$/ ? self.send($1) : super
     end
-    
+  end  
+  
+  def self.config
+    @@sugarfree_config ||= ModuleConfig.new
   end
   
-  #
-  # Instance Methods needed to access the config
-  #
-  module InstanceMethods
-    
-    #
-    # Get the base config (with instance caching), force reload on development
-    # mode!!! (at least when instance caching is not applicable)
-    # 
-    def app_config    
-      @config ||= Config.new(RAILS_ENV != &quot;production&quot;)
+  def self.debug(msg)
+    if config.logger.debug?
+      config.logger.debug &quot;SugarfreeConfig &gt;&gt; DEBUG &gt;&gt; #{msg}&quot;
     end
-    
+  end
+  
+  def self.fatal(msg, e)
+    config.logger.fatal &quot;SugarfreeConfig &gt;&gt; FATAL &gt;&gt; #{msg}&quot;
+    config.logger.fatal e    
   end
   
   #
-  # Include the InstanceMethods to +base+
+  # Adds the the config accessor to +klass+
   #
-  def self.included(base)
-    base.send :include, InstanceMethods
-  end  
-end
+  def self.included(klass)    
   
+    if SugarfreeConfig.config.instance_caching?
+      klass.module_eval %{
+        def #{SugarfreeConfig.config.accessor}
+          @config ||= SugarfreeConfig::Config.new
+        end    
+      }
+    else
+     klass.module_eval %{
+        def #{SugarfreeConfig.config.accessor}
+          SugarfreeConfig::Config.new
+        end    
+      }
+    end
+  end
+end
+</diff>
      <filename>lib/sugarfree_config.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a660e293ddbb29e4087cab764e45cc5cee0fa4d4</id>
    </parent>
  </parents>
  <author>
    <name>David Barral</name>
    <email>david.barral@trabesoluciones.com</email>
  </author>
  <url>http://github.com/davidbarral/sugarfree-config/commit/728a09ff46e6aa293b7336242d983a7baf6344b4</url>
  <id>728a09ff46e6aa293b7336242d983a7baf6344b4</id>
  <committed-date>2008-07-22T02:59:12-07:00</committed-date>
  <authored-date>2008-07-22T02:59:12-07:00</authored-date>
  <message>Major refactor to add new functionalities: configuration and remote config fetching

Lib code splitted in four files
Added mutable configuration to the plugin
Config file con now be fetched locally or through and HTTP connection (from a centralized config server)</message>
  <tree>180708e0f32322c35eaad47cd8bd018103c7548b</tree>
  <committer>
    <name>David Barral</name>
    <email>david.barral@trabesoluciones.com</email>
  </committer>
</commit>
