use-config 0.2.0 → 0.2.1
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/lib/use_config/configuration.rb +17 -5
- data/lib/use_config/version.rb +1 -1
- data/spec/use_config_configuration_spec.rb +10 -2
- data/spec/use_config_spec.rb +6 -1
- metadata +2 -2
@@ -147,8 +147,9 @@ module UseConfig
|
|
147
147
|
#
|
148
148
|
# Options:
|
149
149
|
#
|
150
|
-
# * +:empty
|
151
|
-
# *
|
150
|
+
# * +:empty:+ - Create empty object, don't read configuration from file.
|
151
|
+
# * +:file:+ - Load configuration from given file. Use full name.
|
152
|
+
# * +:path_insert:+ - Insert the value into the config files search path.
|
152
153
|
#
|
153
154
|
# Notes:
|
154
155
|
#
|
@@ -166,13 +167,24 @@ module UseConfig
|
|
166
167
|
end
|
167
168
|
instance_properties.name = name.to_s
|
168
169
|
instance_properties.used_by = []
|
170
|
+
if options[:path_insert]
|
171
|
+
if options[:path_insert].is_a? Array
|
172
|
+
options[:path_insert].reverse.each do |dir|
|
173
|
+
instance_properties['path'].unshift(dir)
|
174
|
+
end
|
175
|
+
else
|
176
|
+
instance_properties['path'].unshift(options[:path_insert])
|
177
|
+
end
|
178
|
+
end
|
169
179
|
if options[:empty]
|
170
180
|
instance_properties.use_file = false
|
171
181
|
end
|
172
|
-
if instance_properties.use_file
|
173
|
-
config_file_find
|
182
|
+
if instance_properties.use_file
|
174
183
|
if instance_properties.file.nil?
|
175
|
-
|
184
|
+
config_file_find
|
185
|
+
if instance_properties.file.nil?
|
186
|
+
raise "Configuration file not found"
|
187
|
+
end
|
176
188
|
end
|
177
189
|
load_configuration
|
178
190
|
end
|
data/lib/use_config/version.rb
CHANGED
@@ -42,8 +42,16 @@ describe UseConfig::Configuration, "instance public interface" do
|
|
42
42
|
context "when option :file given" do
|
43
43
|
it "loads configuration from file" do
|
44
44
|
c = UseConfig::Configuration.new :the_first_conf,
|
45
|
-
:file =>
|
46
|
-
c.core.name.should
|
45
|
+
:file => "spec/config/first_conf.yaml"
|
46
|
+
c.core.name.should == 'first_conf'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when option :path_insert given" do
|
51
|
+
it "loads configuration from file from given path" do
|
52
|
+
c = UseConfig::Configuration.new :config,
|
53
|
+
:path_insert => "spec/config_insert"
|
54
|
+
c.confname.should == 'config_insert_conf'
|
47
55
|
end
|
48
56
|
end
|
49
57
|
end
|
data/spec/use_config_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe UseConfig do
|
|
9
9
|
before :each do
|
10
10
|
UseConfig::Configuration.reset!
|
11
11
|
UseConfig::Configuration.configure do |c|
|
12
|
-
c.path << "
|
12
|
+
c.path << "spec/config"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -31,6 +31,11 @@ describe UseConfig do
|
|
31
31
|
Sample.use_config :first_conf
|
32
32
|
Sample.first_conf.core.name.should == 'first_conf'
|
33
33
|
end
|
34
|
+
|
35
|
+
it "loads configuration from :path_insert directory" do
|
36
|
+
Sample.use_config :config, :path_insert => 'spec/config_insert'
|
37
|
+
Sample.config.confname.should == 'config_insert_conf'
|
38
|
+
end
|
34
39
|
end
|
35
40
|
|
36
41
|
context "Samle class instance" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: use-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Svetoslav Chernobay
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-30 00:00:00 +04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|