profigure 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +3 -2
- data/lib/profigure/profigure.rb +14 -4
- data/profigure.gemspec +4 -3
- data/spec/profigure_spec.rb +24 -1
- data/spec/test_config/like_nested.yml +8 -0
- data/spec/test_config/nested.yml +2 -0
- metadata +4 -3
data/VERSION.yml
CHANGED
data/lib/profigure/profigure.rb
CHANGED
@@ -1,25 +1,35 @@
|
|
1
1
|
class Profigure
|
2
2
|
class << self
|
3
3
|
def load(configs_dir, environment=nil)
|
4
|
-
hash =
|
4
|
+
hash = file_contents("defaults", configs_dir)
|
5
5
|
if environment
|
6
|
-
|
7
|
-
|
8
|
-
hash.recursive_merge!
|
6
|
+
yaml_result = file_contents(environment, configs_dir)
|
7
|
+
merged_with_reference = load_referenced_config_from configs_dir, yaml_result
|
8
|
+
hash.recursive_merge! merged_with_reference
|
9
9
|
end
|
10
10
|
hash["environment"] = environment
|
11
11
|
MoStash.new hash
|
12
12
|
end
|
13
13
|
|
14
|
+
private
|
15
|
+
|
14
16
|
def file_contents(environment, configs_dir)
|
15
17
|
file = "#{configs_dir}/#{environment}.yml"
|
16
18
|
content = run_erb IO.read(file)
|
19
|
+
YAML.load content
|
17
20
|
end
|
18
21
|
|
19
22
|
def run_erb(data)
|
20
23
|
ERB.new( data ).result
|
21
24
|
end
|
22
25
|
|
26
|
+
def load_referenced_config_from( configs_dir, config_hash )
|
27
|
+
config_like_file = config_hash["profigure_like"] || config_hash[:profigure_like]
|
28
|
+
return config_hash unless config_like_file
|
29
|
+
config_like = file_contents( config_like_file, configs_dir )
|
30
|
+
config_like.recursive_merge! config_hash
|
31
|
+
end
|
32
|
+
|
23
33
|
end
|
24
34
|
end
|
25
35
|
|
data/profigure.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{profigure}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joel Friedman"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-18}
|
13
13
|
s.description = %q{profigure aims to be a drop in replacement for configuring your apps in a railsy way.}
|
14
14
|
s.email = %q{asher.friedman@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"spec/test_config/arrays.yml",
|
34
34
|
"spec/test_config/defaults.yml",
|
35
35
|
"spec/test_config/erb.yml",
|
36
|
+
"spec/test_config/like_nested.yml",
|
36
37
|
"spec/test_config/nested.yml",
|
37
38
|
"spec/test_config/overrides.yml",
|
38
39
|
"spec/test_config/test.yml"
|
data/spec/profigure_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Profigure" do
|
4
|
-
before do
|
4
|
+
before :all do
|
5
5
|
@config_dir = File.join(File.dirname(__FILE__), "test_config")
|
6
6
|
end
|
7
7
|
|
@@ -61,4 +61,27 @@ describe "Profigure" do
|
|
61
61
|
|
62
62
|
config[:user].should == ENV["USER"]
|
63
63
|
end
|
64
|
+
|
65
|
+
context "profiguring like another yml" do
|
66
|
+
before :all do
|
67
|
+
@config = Profigure.load @config_dir, "like_nested"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should have the default settings" do
|
71
|
+
@config.foo.should == "bar"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should have settings it's file" do
|
75
|
+
@config.new_config.should == "yes_i_am"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should have settings from config referenced by 'profigure_like'" do
|
79
|
+
@config.marco.should == "polo"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should override configs from refrerenced with actual file" do
|
83
|
+
@config.top_level.second_level.third_level.bar.should == "foo"
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
64
87
|
end
|
data/spec/test_config/nested.yml
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joel Friedman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-18 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- spec/test_config/arrays.yml
|
70
70
|
- spec/test_config/defaults.yml
|
71
71
|
- spec/test_config/erb.yml
|
72
|
+
- spec/test_config/like_nested.yml
|
72
73
|
- spec/test_config/nested.yml
|
73
74
|
- spec/test_config/overrides.yml
|
74
75
|
- spec/test_config/test.yml
|