yaml_properties 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/yaml_properties/version.rb +1 -1
- data/lib/yaml_properties.rb +9 -1
- data/spec/yaml_config_spec.rb +7 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -44,12 +44,12 @@ end
|
|
44
44
|
|
45
45
|
#features/support/env.rb
|
46
46
|
After do |scenario|
|
47
|
-
|
47
|
+
Shutl.reset!
|
48
48
|
end
|
49
49
|
|
50
50
|
#features/step_definitions/egg_steps.rb
|
51
51
|
Given /\AThere are \d+ eggs in a dozen\z/ |dozen|
|
52
|
-
|
52
|
+
Shutl.override_attribute :egg, dozen
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
data/lib/yaml_properties.rb
CHANGED
@@ -15,17 +15,25 @@ module YamlProperties
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def method_missing(key, *args, &block)
|
18
|
-
return properties[key] if
|
18
|
+
return properties[key] if key_present? key
|
19
19
|
|
20
20
|
super key, *args, &block
|
21
21
|
end
|
22
22
|
|
23
|
+
|
23
24
|
def override_attribute attribute, value
|
25
|
+
unless key_present? attribute
|
26
|
+
raise ArgumentError, "Trying to override non-existent property `#{attribute}' with `#{value}'"
|
27
|
+
end
|
24
28
|
properties[attribute] = value
|
25
29
|
end
|
26
30
|
|
27
31
|
private
|
28
32
|
|
33
|
+
def key_present? key
|
34
|
+
properties.keys.include? key.to_s
|
35
|
+
end
|
36
|
+
|
29
37
|
def yaml_file
|
30
38
|
File.join %w(config properties.yml)
|
31
39
|
end
|
data/spec/yaml_config_spec.rb
CHANGED
@@ -26,6 +26,13 @@ describe YamlProperties do
|
|
26
26
|
YamlProperties.life_the_universe_and_everything.should == 42
|
27
27
|
end
|
28
28
|
|
29
|
+
specify "non-existent attribute overrides shouldn't work" do
|
30
|
+
->{
|
31
|
+
YamlProperties.override_attribute :unset_attribute,
|
32
|
+
"let's not allow typos to cause us grief"}.
|
33
|
+
should raise_error ArgumentError
|
34
|
+
end
|
35
|
+
|
29
36
|
specify do
|
30
37
|
YamlProperties.properties.should == properties
|
31
38
|
end
|