Permalink
Browse files

Preparation for release 0.4.0: Refactored core. Updated docs

  • Loading branch information...
1 parent 5cef1c0 commit 02eecad669df553425abafa9e2e865881a02bcdf @rahmal committed Oct 13, 2011
View
17 .gitignore 100644 → 100755
@@ -1,10 +1,21 @@
*.iws
*.ipr
*.iml
+*.log
+*.tmproj
*.swp
*.*~
*~
-.rakeTasks
+.bundle
+.directory
.idea
-*.log
-*.tmproj
+.project
+.redcar
+.rvmrc
+.rakeTasks
+.svn
+.yardoc
+.DS_Store
+log
+tmp
+doc
View
0 doc/classes/ClassVariables.html 100644 → 100755
No changes.
View
0 doc/classes/ConfigError.html 100644 → 100755
No changes.
View
0 doc/classes/ConfigHash.html 100644 → 100755
No changes.
View
0 doc/classes/Constants.html 100644 → 100755
No changes.
View
0 doc/classes/Hash.html 100644 → 100755
No changes.
View
No changes.
View
0 doc/classes/Object.html 100644 → 100755
No changes.
View
No changes.
View
0 doc/classes/RConfig.html 100644 → 100755
No changes.
View
0 doc/created.rid 100644 → 100755
No changes.
View
0 doc/files/README_rdoc.html 100644 → 100755
No changes.
View
No changes.
View
No changes.
View
No changes.
View
No changes.
View
No changes.
View
No changes.
View
No changes.
No changes.
View
No changes.
View
0 doc/files/lib/rconfig_rb.html 100644 → 100755
No changes.
View
0 doc/fr_class_index.html 100644 → 100755
No changes.
View
0 doc/fr_file_index.html 100644 → 100755
No changes.
View
0 doc/fr_method_index.html 100644 → 100755
No changes.
View
0 doc/index.html 100644 → 100755
No changes.
View
0 doc/rdoc-style.css 100644 → 100755
No changes.
View
@@ -8,10 +8,10 @@
#
class ConfigHash < HashWithIndifferentAccess
- # HashWithIndifferentAccess#dup always returns HashWithIndifferentAccess!
- def dup
- self.class.new(self)
- end
+ ##
+ # HashWithIndifferentAccess#default is broken in early versions of Rails.
+ # This is defined to use the hash version in ConfigHash#default
+ define_method(:hash_default, Hash.instance_method(:default))
##
# Dotted notation can be used with arguments (useful for creating mock objects)
@@ -42,47 +42,42 @@ def method_missing(method, *args)
method = method.to_s
value = self[method]
case args.size
- when 0
- # e.g.: RConfig.application.method
- ;
- when 1
- # e.g.: RConfig.application.method(one_arg)
- value = value.send(args[0])
- else
- # e.g.: RConfig.application.method(arg_one, args_two, ...)
- value = value[args]
+ when 0 # e.g.: RConfig.application.method
+ value
+ when 1 # e.g.: RConfig.application.method(one_arg)
+ value.send(args[0])
+ else # e.g.: RConfig.application.method(arg_one, args_two, ...)
+ value[args]
end
+ end
- # value = convert_value(value)
- value
+ ##
+ # HashWithIndifferentAccess#dup always returns HashWithIndifferentAccess!
+ # This is overriden to return ConfigHash (or any other derived class)
+ def dup
+ self.class.new(self)
end
##
# Why the &*#^@*^&$ isn't HashWithIndifferentAccess doing this?
- # HashWithIndifferentAccess doesn't override Hash's []! That's
- # why it's so destructive!
+ # HashWithIndifferentAccess doesn't (or didn't?) override Hash's
+ # []! That's why it's so destructive!
def [](key)
key = key.to_s if key.kind_of?(Symbol)
super(key)
end
- # HashWithIndifferentAccess#default is broken!
- define_method(:default_Hash, Hash.instance_method(:default))
-
##
# Allow hash.default => hash['default']
# without breaking Hash's usage of default(key)
- @@no_key = [:no_key] # magically unique value.
def default(key = @@no_key)
key = key.to_s if key.is_a?(Symbol)
- key == @@no_key ? self['default'] : default_Hash(key == @@no_key ? nil : key)
+ key == @@no_key ? self['default'] : hash_default(key)
end
##
- # HashWithIndifferentAccess#update is broken!
- # Hash#update returns self,
- # BUT,
- # HashWithIndifferentAccess#update does not!
+ # HashWithIndifferentAccess#update is broken in early versions of Rails
+ # Hash#update returns self, BUT, HashWithIndifferentAccess#update does not!
#
# { :a => 1 }.update({ :b => 2, :c => 3 })
# => { :a => 1, :b => 2, :c => 3 }
@@ -97,11 +92,10 @@ def update(hash)
end
##
- # Override WithIndifferentAccess#convert_value
+ # Override HashWithIndifferentAccess#convert_value
# return instances of this class for Hash values.
def convert_value(value)
- # STDERR.puts "convert_value(#{value.inspect}:#{value.class})"
- value.class == Hash ? self.class.new(value).freeze : value
+ [Hash, HashWithIndifferentAccess].include?(value.class) ? self.class.new(value).freeze : value
end
end # class ConfigHash
View
0 lib/rconfig/core_ext/object.rb 100644 → 100755
No changes.
View
0 lib/rconfig/logger.rb 100644 → 100755
No changes.
View
2 lib/rconfig/mixins.rb 100644 → 100755
@@ -5,6 +5,6 @@
require 'rconfig/mixins/class_variables'
require 'rconfig/mixins/config_paths'
require 'rconfig/mixins/constants'
-require 'rconfig/mixins/loader'
+require 'rconfig/mixins/reload'
require 'rconfig/mixins/overlay'
require 'rconfig/mixins/utils'
View
0 lib/rconfig/mixins/callbacks.rb 100644 → 100755
No changes.
View
@@ -53,5 +53,19 @@ module ClassVariables
# A hash of each file that has been loaded.
@@config_file_loaded = nil
+
+ # Magically unique value. Used to provide a key to retrieve a default value
+ # specified in a config file. The symbol is wrapped in an array so that it will
+ # not be treated like a normal key and changed to a string.
+ #
+ # Example:
+ # currency:
+ # us: dollar
+ # gb: pound
+ # default: dollar
+ #
+ # RConfig.currency.ca => 'dollar'
+ @@no_key = [:no_key]
+
end
end
View
@@ -1,5 +1,5 @@
module Mixins
- module ConfingPaths
+ module ConfigPaths
##
# Sets the list of directories to search for
View
0 lib/rconfig/mixins/constants.rb 100644 → 100755
No changes.
View
0 lib/rconfig/mixins/overlay.rb 100644 → 100755
No changes.
View
0 lib/rconfig/mixins/reload.rb 100644 → 100755
No changes.
View
0 lib/rconfig/mixins/utils.rb 100644 → 100755
No changes.
View
@@ -64,6 +64,8 @@ class RConfig
Mixins::ConfigPaths, Mixins::Overlay,
Mixins::Reload, Mixins::Callbacks, Mixins::Utils
+ create_logger
+
##
# Convenience method to initialize necessary fields including,
# config path(s), overlay, allow_reload, and log_level, all at
@@ -75,14 +77,14 @@ class RConfig
def self.initialize(*args)
logger.info { "Initialing RConfig" }
case args[0]
- when Hash
- params = args[0].symbolize_keys
- paths = params[:paths]
- overlay = params[:overlay]
- reload = params[:reload]
- loglvl = params[:log_level]
- else
- paths, overlay, reload, loglvl = * args
+ when Hash
+ params = args[0].symbolize_keys
+ paths = params[:paths]
+ overlay = params[:overlay]
+ reload = params[:reload]
+ loglvl = params[:log_level]
+ else
+ paths, overlay, reload, loglvl = *args
end
logger.debug { "PATHS: #{paths}\nOVERLAY: #{overlay}\nRELOAD: #{reload}\nLOG_LEVEL: #{loglvl}" }
self.config_paths = paths
@@ -283,7 +285,7 @@ def self.reload_on_change(name)
##
- # This method provides shorthand to retrieve confiuration data that
+ # This method provides shorthand to retrieve configuration data that
# is global in scope, and used on an application or environment-wide
# level. The default location that it checks is the application file.
# The application config file is a special config file that should be
View
0 spec/spec.opts 100644 → 100755
No changes.
View
0 spec/spec_helper.rb 100644 → 100755
No changes.
View
0 test/config_files/my_class.yml 100644 → 100755
No changes.
View
0 test/config_files/test.yml 100644 → 100755
No changes.

0 comments on commit 02eecad

Please sign in to comment.