Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion configuration.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ Gem::Specification::new do |spec|
"samples/e.rb",
"samples/f.rb",
"test",
"test/defaults_test.rb",
"test/overwrite_test.rb"]

spec.executables = []

spec.require_path = "lib"

spec.test_files = nil
Expand Down
19 changes: 13 additions & 6 deletions lib/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def load name
Table[key]
end
end
send :extend, ClassMethods
send :extend, ClassMethods

module InstanceMethods
attr 'name'
Expand Down Expand Up @@ -113,7 +113,7 @@ class DSL

instance_methods.each do |m|
undef_method m unless m[Protected]
end
end

Kernel.methods.each do |m|
next if m[Protected]
Expand All @@ -134,8 +134,15 @@ def Method m

def self.evaluate configuration, options = {}, &block
dsl = new configuration

options.each{|key, value| Pure[dsl].send key, value}

options.each do |key, value|
if value.is_a?(Hash)
Pure[dsl].send key, evaluate(dsl, value)
else
Pure[dsl].send key, value
end
end

Pure[dsl].instance_eval(&block) if block

Pure[dsl].instance_eval{ @__configuration }
Expand Down Expand Up @@ -164,7 +171,7 @@ def method_missing(m, *a, &b)
name = m.to_s
configuration =
if @__configuration.respond_to?(name) and Configuration === @__configuration.send(name)
@__configuration.send name
@__configuration.send name
else
Configuration.new name
end
Expand Down Expand Up @@ -208,7 +215,7 @@ class Pure
::Object.instance_methods.each do |m|
Instance_Methods[m.to_s] = ::Object.instance_method m
undef_method m unless m[Protected]
end
end

def method_missing m, *a, &b
Instance_Methods[m.to_s].bind(@object).call(*a, &b)
Expand Down
26 changes: 26 additions & 0 deletions test/defaults_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'minitest/autorun'
require 'configuration.rb'

describe Configuration do

before do
@b = Configuration.for('b') {
host "codeforpeople.com"

mail {
host "gmail.com"
}
}

@c = Configuration.for('c', @b) {
foo 'bar'
}
end

it "must return default values" do
@b.host.must_equal @c.host
@b.mail.must_equal @c.mail
@b.mail.host.must_equal @c.mail.host
end

end