yacht 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +7 -4
- data/features/load.feature +1 -1
- data/features/step_definitions/loader_steps.rb +15 -7
- data/lib/yacht/javascript.rb +1 -3
- data/lib/yacht/loader.rb +20 -17
- data/lib/yacht/version.rb +1 -1
- data/spec/yacht/loader_spec.rb +46 -8
- data/yacht.gemspec +1 -1
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -22,10 +22,13 @@ Yacht is an application configuration gem that lets you define settings for mult
|
|
22
22
|
|
23
23
|
=== Step 1: YAML files
|
24
24
|
|
25
|
-
First create
|
25
|
+
First create one or more of the following YAML files in the same directory to define your settings:
|
26
26
|
|
27
27
|
# config/yacht/base.yml (required)
|
28
28
|
production:
|
29
|
+
public_info:
|
30
|
+
copyright_year: 2011
|
31
|
+
company_name: AT&T Interactive
|
29
32
|
cdn_host: 1.2.3.4
|
30
33
|
super_secret_info:
|
31
34
|
aws_key: foofoo
|
@@ -38,7 +41,7 @@ First create two (or more) YAML files in the same directory to define your setti
|
|
38
41
|
# see https://gist.github.com/979804 for an explanation
|
39
42
|
aws_key: bazbaz
|
40
43
|
|
41
|
-
# config/yacht/whitelist.yml (
|
44
|
+
# config/yacht/whitelist.yml (optional)
|
42
45
|
# any keys specified here can be used as a whitelist filter:
|
43
46
|
# Yacht::Loader.to_hash(:apply_whitelist? => true)
|
44
47
|
# or
|
@@ -47,7 +50,7 @@ First create two (or more) YAML files in the same directory to define your setti
|
|
47
50
|
# NOTE: the whitelist is ignored when using Yacht.my_key or Yacht['my_key']
|
48
51
|
# you have to use Yacht::Loader#to_hash or
|
49
52
|
# Yacht::Loader#to_classy_struct to use the whitelist
|
50
|
-
-
|
53
|
+
- public_info
|
51
54
|
|
52
55
|
# config/yacht/local.yml (optional)
|
53
56
|
# any values set in local.yml will override values set in base.yml
|
@@ -108,4 +111,4 @@ When using Yacht inside of a Rails application, you can use the yacht_js_snippet
|
|
108
111
|
|
109
112
|
== License
|
110
113
|
|
111
|
-
Yacht is licensed under the MIT License with one addition: The Software shall be used for Good, not Evil.
|
114
|
+
Yacht is licensed under the MIT License with one addition: The Software shall be used for Good, not Evil.
|
data/features/load.feature
CHANGED
@@ -13,10 +13,9 @@ end
|
|
13
13
|
|
14
14
|
|
15
15
|
Then /^the constant "([^"]*)" should contain the following hash:$/ do |constant_name, stringified|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# i t can be compared against hashes using `==`
|
16
|
+
# don't forget to tack on to_hash to avoid weird errors
|
17
|
+
# TODO: make ClassyStruct more Hash-like so it can be compared against hashes using `==`
|
18
|
+
stringified_hash_should_match( stringified, Object.const_get(constant_name).to_hash )
|
20
19
|
end
|
21
20
|
|
22
21
|
When /^I load Yacht with environment: "([^"]*)"$/ do |env|
|
@@ -24,9 +23,18 @@ When /^I load Yacht with environment: "([^"]*)"$/ do |env|
|
|
24
23
|
end
|
25
24
|
|
26
25
|
Then /^Yacht should contain the following hash:$/ do |stringified|
|
27
|
-
hash = eval(stringified)
|
28
|
-
|
29
26
|
in_current_dir do
|
30
|
-
Yacht::Loader.to_hash
|
27
|
+
stringified_hash_should_match(stringified, Yacht::Loader.to_hash)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module LoaderHelpers
|
32
|
+
def stringified_hash_should_match(string, hash)
|
33
|
+
hash_from_string = eval(string)
|
34
|
+
|
35
|
+
in_current_dir do
|
36
|
+
hash_from_string.should == hash
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
40
|
+
World(LoaderHelpers)
|
data/lib/yacht/javascript.rb
CHANGED
@@ -13,9 +13,7 @@ class Yacht::Loader
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def js_keys
|
16
|
-
load_config_file(:js_keys, :expect_to_load => Array) ||
|
17
|
-
raise Yacht::LoadError.new("Couldn't load js_keys")
|
18
|
-
end
|
16
|
+
load_config_file(:js_keys, :expect_to_load => Array) || raise( Yacht::LoadError.new("Couldn't load js_keys") )
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
data/lib/yacht/loader.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# TODO: Rename YachtLoader to Yacht and somehow incorporate ClassyStruct
|
2
|
-
|
3
1
|
class Yacht::Loader
|
4
2
|
class << self
|
5
3
|
def environment
|
@@ -16,7 +14,9 @@ class Yacht::Loader
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def config_file_for(config_type)
|
19
|
-
|
17
|
+
if !valid_config_types.include?(config_type.to_s)
|
18
|
+
raise Yacht::LoadError.new "#{config_type} is not a valid config type"
|
19
|
+
end
|
20
20
|
|
21
21
|
full_file_path_for_config(config_type)
|
22
22
|
end
|
@@ -69,8 +69,9 @@ class Yacht::Loader
|
|
69
69
|
file_name = self.config_file_for(file_type)
|
70
70
|
loaded = self._load_config_file(file_name)
|
71
71
|
|
72
|
-
# YAML contained the wrong type
|
73
|
-
|
72
|
+
if loaded && !loaded.is_a?(expected_class) # YAML contained the wrong type
|
73
|
+
raise Yacht::LoadError.new "#{file_name} must contain #{expected_class} (got #{loaded.class})"
|
74
|
+
end
|
74
75
|
|
75
76
|
loaded
|
76
77
|
rescue => e
|
@@ -78,25 +79,27 @@ class Yacht::Loader
|
|
78
79
|
if e.is_a? Yacht::LoadError
|
79
80
|
raise e
|
80
81
|
else
|
81
|
-
# convert other errors to
|
82
|
+
# convert other errors to Yacht::LoadError
|
82
83
|
raise Yacht::LoadError.new "ERROR: loading config file: '#{file_type}': #{e}"
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
86
87
|
def chain_configs(config, env)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
88
|
+
if config.has_key?(env)
|
89
|
+
parent = if parent_env = config[env]['_parent']
|
90
|
+
raise Yacht::LoadError.new "environment '#{parent_env}' does not exist" unless config.has_key?(parent_env)
|
91
|
+
chain_configs(config, config[env]['_parent'])
|
92
|
+
else
|
93
|
+
config['default'] || {}
|
94
|
+
end
|
95
|
+
|
96
|
+
parent.deep_merge(config[env])
|
97
|
+
else
|
98
|
+
config['default'] || {}
|
99
|
+
end
|
96
100
|
end
|
97
101
|
end
|
98
|
-
|
99
102
|
end
|
100
103
|
|
101
104
|
# Alias for Yacht::Loader for backwards compatibility
|
102
|
-
Object.const_set(:YachtLoader, Yacht::Loader)
|
105
|
+
Object.const_set(:YachtLoader, Yacht::Loader)
|
data/lib/yacht/version.rb
CHANGED
data/spec/yacht/loader_spec.rb
CHANGED
@@ -38,13 +38,6 @@ describe Yacht::Loader do
|
|
38
38
|
subject.to_hash(:env => 'wacky').should == mock_base_config['wacky']
|
39
39
|
end
|
40
40
|
|
41
|
-
it "raises an error if an environment is requested that doesn't exist" do
|
42
|
-
expect {
|
43
|
-
subject.environment = 'nonexistent'
|
44
|
-
subject.to_hash
|
45
|
-
}.to raise_error( Yacht::LoadError, /does not exist/)
|
46
|
-
end
|
47
|
-
|
48
41
|
context "with inheritance" do
|
49
42
|
let(:mock_base_config_with_inheritance) do
|
50
43
|
{
|
@@ -87,6 +80,36 @@ describe Yacht::Loader do
|
|
87
80
|
}
|
88
81
|
end
|
89
82
|
end
|
83
|
+
|
84
|
+
context "with inheritance when a parent is missing" do
|
85
|
+
let(:mock_base_config_with_inheritance) do
|
86
|
+
{
|
87
|
+
'default' => {
|
88
|
+
:doggies => {
|
89
|
+
'lassie' => 'nice',
|
90
|
+
'cujo' => 'mean'
|
91
|
+
}
|
92
|
+
},
|
93
|
+
'kid' => {
|
94
|
+
'_parent' => 'deadbeat_dad',
|
95
|
+
:doggies => {
|
96
|
+
'cerberus' => '3-headed'
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
before do
|
103
|
+
subject.stub(:base_config).and_return(mock_base_config_with_inheritance)
|
104
|
+
subject.environment = 'kid'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "raises an error if an environment is requested whose parent doesn't exist" do
|
108
|
+
expect {
|
109
|
+
subject.to_hash
|
110
|
+
}.to raise_error( Yacht::LoadError, /does not exist/)
|
111
|
+
end
|
112
|
+
end
|
90
113
|
end
|
91
114
|
|
92
115
|
describe :all do
|
@@ -104,6 +127,21 @@ describe Yacht::Loader do
|
|
104
127
|
subject.environment = 'wacky'
|
105
128
|
subject.to_hash[:color_of_the_day].should == 'purple'
|
106
129
|
end
|
130
|
+
|
131
|
+
it "returns the defaults for environments that do not exist" do
|
132
|
+
subject.stub(:base_config).and_return({
|
133
|
+
'default' => {
|
134
|
+
:color_of_the_day => 'orange',
|
135
|
+
},
|
136
|
+
'wacky' => {
|
137
|
+
:color_of_the_day => 'purple',
|
138
|
+
}
|
139
|
+
})
|
140
|
+
subject.stub(:local_config).and_return({})
|
141
|
+
|
142
|
+
subject.environment = 'nerdy'
|
143
|
+
subject.to_hash.should == {:color_of_the_day => 'orange'}
|
144
|
+
end
|
107
145
|
end
|
108
146
|
|
109
147
|
describe :base_config do
|
@@ -246,4 +284,4 @@ describe YachtLoader do
|
|
246
284
|
it "should alias YachtLoader to Yacht::Loader for backwards compatibility" do
|
247
285
|
::YachtLoader.should == Yacht::Loader
|
248
286
|
end
|
249
|
-
end
|
287
|
+
end
|
data/yacht.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_dependency "json"
|
20
20
|
|
21
21
|
s.add_development_dependency "gherkin", '>= 2.4.0'
|
22
|
-
s.add_development_dependency "cucumber", '
|
22
|
+
s.add_development_dependency "cucumber", '~> 1.0'
|
23
23
|
s.add_development_dependency 'aruba'
|
24
24
|
s.add_development_dependency "rspec", '>= 2.6.0'
|
25
25
|
s.add_development_dependency "simplecov", '>= 0.4.1'
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: yacht
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mani Tadayon
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-
|
14
|
+
date: 2011-07-01 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -53,9 +53,9 @@ dependencies:
|
|
53
53
|
requirement: &id004 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
55
55
|
requirements:
|
56
|
-
- -
|
56
|
+
- - ~>
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
version:
|
58
|
+
version: "1.0"
|
59
59
|
type: :development
|
60
60
|
version_requirements: *id004
|
61
61
|
- !ruby/object:Gem::Dependency
|
@@ -166,7 +166,7 @@ rubyforge_project:
|
|
166
166
|
rubygems_version: 1.3.9.2
|
167
167
|
signing_key:
|
168
168
|
specification_version: 3
|
169
|
-
summary: yacht-0.2.
|
169
|
+
summary: yacht-0.2.6
|
170
170
|
test_files:
|
171
171
|
- spec/monkeypatches/rails_helper_spec.rb
|
172
172
|
- spec/spec_helper.rb
|