Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support for loading entire directories of configs.

  • Loading branch information...
commit dd8880c0b338d58c09ffd446d71c3465b2382385 1 parent f305400
@PatrickTulskie authored
View
16 lib/configster/configster.rb
@@ -33,14 +33,20 @@ def raw_configster
# ===========================
def self.load!(configster_config)
@configster_config ||= { }
- new_config = case configster_config
+ case configster_config
when Hash
- configster_config
+ @configster_config.merge!(configster_config)
when String
- YAML.load_file(configster_config)
+ if File.directory?(configster_config)
+ Dir.glob(File.join(configster_config, "*.yml")).each do |file|
+ @configster_config.merge!(YAML.load_file(file))
+ end
+ elsif File.exists?(configster_config)
+ @configster_config.merge!(YAML.load_file(configster_config))
+ else
+ raise "Unable to locate #{configster_config}"
+ end
end
-
- @configster_config.merge!(new_config)
end
def self.config_for(klass)
View
11 spec/configster_spec.rb
@@ -2,13 +2,22 @@
describe Configster do
- subject { Configster }
+ subject do
+ Configster.load!(File.join($spec_root, 'configurations', 'test_configuration.yml'))
+ Configster
+ end
+
it { should respond_to(:config_for) }
it "should be able to load the configuration for a specific class" do
Configster.config_for(KonfiguredKlass).should_not be_nil
end
+ it "should be able to load a directory of yml files" do
+ Configster.load!(File.join($spec_root, 'configurations'))
+ Configster.config_for('SecondConfiguration').should_not be_nil
+ end
+
it "should not destroy other configurations when loading additional configs" do
Configster.load!('test_thing' => { 'test' => true })
Configster.config_for('test_thing').test.should be_true
View
4 spec/configurations/second_configuration.yml
@@ -0,0 +1,4 @@
+SecondConfiguration:
+ user_name: configster
+ password: bacon
+ tag_line: "Okay..."
View
1  spec/konfigured_klass_spec.rb
@@ -3,6 +3,7 @@
describe KonfiguredKlass do
before(:all) do
+ Configster.load!(File.join($spec_root, 'configurations', 'test_configuration.yml'))
@test_klass = KonfiguredKlass.new
end
View
2  spec/spec_helper.rb
@@ -26,8 +26,6 @@ def p(s)
end
end
-Configster.load!(File.join($spec_root, 'configurations', 'test_configuration.yml'))
-
class KonfiguredKlass
include Configster
end
Please sign in to comment.
Something went wrong with that request. Please try again.