use-config 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -147,8 +147,9 @@ module UseConfig
147
147
  #
148
148
  # Options:
149
149
  #
150
- # * +:empty: - Create empty object, don't read configuration from file.
151
- # * No other options yet.
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 and instance_properties.file.nil?
173
- config_file_find
182
+ if instance_properties.use_file
174
183
  if instance_properties.file.nil?
175
- raise "Configuration file not found"
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
@@ -1,4 +1,4 @@
1
1
  module UseConfig
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
4
4
 
@@ -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 => 'first_conf.yaml'
46
- c.core.name.should = 'first_conf'
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
@@ -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 << "#{File.dirname(__FILE__)}/config"
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.0
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-08 00:00:00 +03:00
13
+ date: 2011-03-30 00:00:00 +04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency