Skip to content
Browse files

added support for multiple yaml files

  • Loading branch information...
1 parent 4d31309 commit 1c282b9192d081bdb716cc936bfaaceae077360e @yhuang committed Jul 7, 2012
Showing with 37 additions and 18 deletions.
  1. +20 −2 lib/timed_config.rb
  2. +17 −16 spec/timed_config/gems_spec.rb
View
22 lib/timed_config.rb
@@ -14,8 +14,21 @@ def path
def path=(p)
@path = p
reload true
+ @paths = [p]
p
end
+
+ def paths
+ return @paths unless @paths.nil? || @paths.empty?
+ path.nil? ? [] : [path]
+ end
+
+ def paths=(p)
+ @paths = paths
+ @paths.push(p)
+ reload true
+ @paths
+ end
def period
@period || 60
@@ -29,8 +42,13 @@ def period=(p)
def reload(force=false)
if force || !@last_load || Time.now >= (@last_load + period)
- if TimedConfig.path && File.exists?(TimedConfig.path)
- @config = YAML::load(File.open(TimedConfig.path))
+ p_array = paths
+
+ unless p_array.empty?
+ @config = {}
+ p_array.each do |p|
+ @config.merge!(YAML::load(File.open(p))) if File.exists? p
+ end
else
@config = nil
end
View
33 spec/timed_config/gems_spec.rb
@@ -80,12 +80,13 @@
end
it "should return proper values for Gems.dependencies" do
- TimedConfig::Gems.dependencies.should == [ :rake, :mysql ]
+ TimedConfig::Gems.dependencies.should be == [ :rake, :mysql ]
TimedConfig::Gems.development_dependencies.should == []
end
it "should return proper values for Gems.gemset_names" do
- TimedConfig::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
+ puts TimedConfig::Gems.gemset_names.class
+ TimedConfig::Gems.gemset_names.should =~ [ :default, :rspec2, :solo ]
end
end
@@ -125,12 +126,12 @@
end
it "should return proper values for Gems.dependencies" do
- TimedConfig::Gems.dependencies.should == [ :rake, :mysql2 ]
+ TimedConfig::Gems.dependencies.should be == [ :rake, :mysql2 ]
TimedConfig::Gems.development_dependencies.should == []
end
it "should return proper values for Gems.gemset_names" do
- TimedConfig::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
+ TimedConfig::Gems.gemset_names.should =~ [ :default, :rspec2, :solo ]
end
end
@@ -166,12 +167,12 @@
end
it "should return proper values for Gems.dependencies" do
- TimedConfig::Gems.dependencies.should == [:rake]
+ TimedConfig::Gems.dependencies.should be == [:rake]
TimedConfig::Gems.development_dependencies.should == []
end
it "should return proper values for Gems.gemset_names" do
- TimedConfig::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
+ TimedConfig::Gems.gemset_names.should =~ [ :default, :rspec2, :solo ]
end
end
@@ -181,8 +182,8 @@
end
it "should set everything to nil" do
- TimedConfig::Gems.gemset.should == nil
- TimedConfig::Gems.gemsets.should == nil
+ TimedConfig::Gems.gemset.should be == nil
+ TimedConfig::Gems.gemsets.should be == nil
TimedConfig::Gems.versions.should == nil
end
end
@@ -224,14 +225,14 @@
end
it "should create methods from keys of @gemspec" do
- TimedConfig::Gems.gemspec.name.should == "name"
- TimedConfig::Gems.gemspec.version.should == "0.1.0"
- TimedConfig::Gems.gemspec.authors.should == ["Author"]
- TimedConfig::Gems.gemspec.email.should == "email@email.com"
- TimedConfig::Gems.gemspec.homepage.should == "http://github.com/author/name"
- TimedConfig::Gems.gemspec.summary.should == "Summary"
- TimedConfig::Gems.gemspec.description.should == "Description"
- TimedConfig::Gems.gemspec.dependencies.should == [
+ TimedConfig::Gems.gemspec.name.should be == "name"
+ TimedConfig::Gems.gemspec.version.should be == "0.1.0"
+ TimedConfig::Gems.gemspec.authors.should be == ["Author"]
+ TimedConfig::Gems.gemspec.email.should be == "email@email.com"
+ TimedConfig::Gems.gemspec.homepage.should be == "http://github.com/author/name"
+ TimedConfig::Gems.gemspec.summary.should be == "Summary"
+ TimedConfig::Gems.gemspec.description.should be == "Description"
+ TimedConfig::Gems.gemspec.dependencies.should be == [
"rake",
{ "default" => ["mysql"] },
{ "rspec2" => [ "mysql2" ] }

0 comments on commit 1c282b9

Please sign in to comment.
Something went wrong with that request. Please try again.