Permalink
Browse files

nested configurations from DSLs

  • Loading branch information...
1 parent 88db056 commit 986eabc085ac3d24ceb7c4acab9b30a290ca3da3 @gfowley gfowley committed May 1, 2012
Showing with 322 additions and 131 deletions.
  1. +1 −1 Gemfile.lock
  2. +1 −2 README.md
  3. +10 −9 lib/iqeo/configuration.rb
  4. +310 −119 spec/configuration_spec.rb
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- iqeo-conf (0.0.4)
+ iqeo-conf (0.0.6)
GEM
remote: https://rubygems.org/
View
@@ -98,8 +98,7 @@ Need time (have motivation)...
* Load configurations from a string or file after creation / in DSL block
* Option to get hash directly to prevent polluting namespace with delegated hash methods
* Blank slate for DSL ? - optional ?
-* Global configuration - watch for collisions ?
-* Issues around deferred interpolation / procs / lambdas etc...
+* Consider issues around deferred interpolation / procs / lambdas etc...
* Load other formats into configuration - YAML, CSV, ...anything Enumerable should be easy enough.
## License
View
@@ -2,15 +2,15 @@
require_relative "configuration/version"
require_relative "configuration/hash_with_indifferent_access"
+# fix: nested configurations broken for DSL !!
+# todo: clean DSL syntax for creating a configuration - just a block ?
# todo: configuration file load path - array of Dir.glob like file specs ?
# todo: use an existing configuration for defaults
-# todo: clean DSL syntax for creating a configuration - just a block ?
# todo: load configurations from a string or file after creation / in DSL block
# todo: option to get hash directly to prevent polluting namespace with delegated hash methods
# todo: blank slate for DSL - optional ?
-# todo: global configuration - watch for collisions ?
-# todo: deferred interpolation / procs / lambdas etc...
-# todo: load other formats from string & file - YAML, XML?
+# todo: consider issues around deferred interpolation / procs / lambdas etc...
+# todo: load other formats from string & file - YAML, CSV, ...anything Enumerable should be easy enough.
module Iqeo
@@ -42,18 +42,19 @@ def initialize &block
end
end
- def method_missing name, *values
- return @items.send name, *values if @items.respond_to? name
+ def method_missing name, *values, &block
+ return @items.send name, *values if @items.respond_to? name # @items methods are highest priority
# this is unreachable since these methods are delegated to @items hash
# but keep it around for when we make selective delegation an option
#case name
#when :[]= then return _set values.shift, values.size > 1 ? values : values.first
#when :[] then return _get values.shift
#end
name = name.to_s.chomp('=') # todo: write a test case for a non-string object as key being converted by .to_s
- return _get name if values.empty?
- return _set name, values if values.size > 1
- return _set name, values.first
+ return _set name, Configuration.new( &block ) if block_given? # block is a nested configuration
+ return _get name if values.empty? # just get item
+ return _set name, values if values.size > 1 # set item to multiple values
+ return _set name, values.first # set item to single value
end
attr_accessor :_parent # todo: should attr_writer be protected ?
Oops, something went wrong.

0 comments on commit 986eabc

Please sign in to comment.