Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from yhuang/master

Upgrade for Cobrand Administration
  • Loading branch information...
commit cf246cf616c1c129e7c31e46fab9aa9bc0bc2a5f 2 parents 4d31309 + ae5a44a
@winton authored
View
26 lib/timed_config.rb
@@ -2,7 +2,7 @@
module TimedConfig
class <<self
-
+
def config
reload
end
@@ -14,8 +14,22 @@ 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 add_path(p)
+ @paths = [] if @paths.nil?
+ @paths.push path unless path.nil? || @paths.include?(path)
+ @paths.push p unless @paths.include?(p)
+ reload true
+ @paths
+ end
def period
@period || 60
@@ -29,8 +43,14 @@ 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|
+ yaml_hash = YAML::load(File.open p) if File.exists? p
+ @config.merge!(yaml_hash) if yaml_hash.is_a?(Hash)
+ end
else
@config = nil
end
View
3  spec/spec_helper.rb
@@ -10,7 +10,6 @@
Spec::Runner.configure do |config|
end
-def write_to_fixture(data)
- config = "#{$root}/spec/fixtures/config.yml"
+def write_to_fixture(data, config="#{$root}/spec/fixtures/config.yml")
File.open(config, 'w') {|f| f.write(data) }
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" ] }
View
11 spec/timed_config_spec.rb
@@ -1,9 +1,12 @@
require 'spec_helper'
describe TimedConfig do
+ config = "#{$root}/spec/fixtures/config.yml"
+ another_config = "#{$root}/spec/fixtures/another_config.yml"
after(:all) do
- FileUtils.rm "#{$root}/spec/fixtures/config.yml"
+ FileUtils.rm config
+ FileUtils.rm another_config
end
it "should not have set a config" do
@@ -32,4 +35,10 @@
sleep 1
TimedConfig.config.should == { 'test3' => 'test3' }
end
+
+ it "should include config from two files" do
+ write_to_fixture "test4: test4", another_config
+ TimedConfig.add_path another_config
+ TimedConfig.config.should == { 'test3' => 'test3', 'test4' => 'test4' }
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.