Skip to content

Commit

Permalink
nested configurations from DSLs
Browse files Browse the repository at this point in the history
  • Loading branch information
gfowley committed May 1, 2012
1 parent 88db056 commit 986eabc
Show file tree
Hide file tree
Showing 4 changed files with 322 additions and 131 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
iqeo-conf (0.0.4) iqeo-conf (0.0.6)


GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -98,8 +98,7 @@ Need time (have motivation)...
* Load configurations from a string or file after creation / in DSL block * 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 * Option to get hash directly to prevent polluting namespace with delegated hash methods
* Blank slate for DSL ? - optional ? * Blank slate for DSL ? - optional ?
* Global configuration - watch for collisions ? * Consider issues around deferred interpolation / procs / lambdas etc...
* Issues around deferred interpolation / procs / lambdas etc...
* Load other formats into configuration - YAML, CSV, ...anything Enumerable should be easy enough. * Load other formats into configuration - YAML, CSV, ...anything Enumerable should be easy enough.


## License ## License
Expand Down
19 changes: 10 additions & 9 deletions lib/iqeo/configuration.rb
Expand Up @@ -2,15 +2,15 @@
require_relative "configuration/version" require_relative "configuration/version"
require_relative "configuration/hash_with_indifferent_access" 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: configuration file load path - array of Dir.glob like file specs ?
# todo: use an existing configuration for defaults # 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: 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: option to get hash directly to prevent polluting namespace with delegated hash methods
# todo: blank slate for DSL - optional ? # todo: blank slate for DSL - optional ?
# todo: global configuration - watch for collisions ? # todo: consider issues around deferred interpolation / procs / lambdas etc...
# todo: deferred interpolation / procs / lambdas etc... # todo: load other formats from string & file - YAML, CSV, ...anything Enumerable should be easy enough.
# todo: load other formats from string & file - YAML, XML?


module Iqeo module Iqeo


Expand Down Expand Up @@ -42,18 +42,19 @@ def initialize &block
end end
end end


def method_missing name, *values def method_missing name, *values, &block
return @items.send name, *values if @items.respond_to? name 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 # this is unreachable since these methods are delegated to @items hash
# but keep it around for when we make selective delegation an option # but keep it around for when we make selective delegation an option
#case name #case name
#when :[]= then return _set values.shift, values.size > 1 ? values : values.first #when :[]= then return _set values.shift, values.size > 1 ? values : values.first
#when :[] then return _get values.shift #when :[] then return _get values.shift
#end #end
name = name.to_s.chomp('=') # todo: write a test case for a non-string object as key being converted by .to_s 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, Configuration.new( &block ) if block_given? # block is a nested configuration
return _set name, values if values.size > 1 return _get name if values.empty? # just get item
return _set name, values.first return _set name, values if values.size > 1 # set item to multiple values
return _set name, values.first # set item to single value
end end


attr_accessor :_parent # todo: should attr_writer be protected ? attr_accessor :_parent # todo: should attr_writer be protected ?
Expand Down

0 comments on commit 986eabc

Please sign in to comment.