simple-conf 0.1.2 → 0.2.0
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.
- checksums.yaml +15 -0
- data/.vimrc +5 -0
- data/config/options2.local.yml +2 -0
- data/config/options2.yml +2 -0
- data/lib/simple-conf/loader.rb +19 -13
- data/lib/simple-conf/version.rb +1 -1
- data/spec/simple_conf_spec.rb +28 -16
- data/spec/spec_helper.rb +8 -0
- metadata +8 -15
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
NzdmMGFjYjEyYmZhYWQxOGUzNzRlN2ZlYmY4ZGMxZWZlMDdiODBiMg==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
YzhjNTM5ZWQyMWFlNmYzNzBkNzNjZjVhN2U4YzhiMTJhYTdkODcyZg==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
Y2M4NDMwYmY2YzZhZDI3ZTMyNDZhMjRkY2NiMDRlYmRmNWUwYTFlNzZlODgy
|
|
10
|
+
MTU0YTQ5MmUyYjk5YTVjMzg4ODgxMzk4NTg2MmVkMzFlNjQxMDg2MjcwNzY1
|
|
11
|
+
MjhmYjdhMjVkMTZlZDhhOWI5ODlmMTg0ODEwNWI3MTNkYzZjMGQ=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
Y2MxNmEzN2JhYTYxN2QxM2EzYTMwMjlmMmU5MGNkNWQxZTRhNDdkODUzMmY1
|
|
14
|
+
NTdkNjA4ZjJmZGRmZDU5N2RiMzEyZDVhZTFhM2E1Nzc5Yzc4ZWQ2MzQ5Mjdh
|
|
15
|
+
NDBhZWZjYTdhY2VjMmVjMGY2NThkNGNmMjU2MWE4Y2EyYTQyNDI=
|
data/.vimrc
ADDED
data/config/options2.yml
ADDED
data/lib/simple-conf/loader.rb
CHANGED
|
@@ -5,30 +5,36 @@ require 'erb'
|
|
|
5
5
|
module SimpleConf
|
|
6
6
|
Loader = Struct.new(:klass) do
|
|
7
7
|
def run
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
paths.each do |path|
|
|
9
|
+
yaml_file(path).each_pair do |key, value|
|
|
10
|
+
set(key, value)
|
|
11
|
+
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
yaml_file(path).fetch(Rails.env, {}).each_pair do |key, value|
|
|
14
|
+
set(key, value)
|
|
15
|
+
end if rails_environment_defined?
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
yaml_file(path).fetch(klass.env, {}).each_pair do |key, value|
|
|
18
|
+
set(key, value)
|
|
19
|
+
end if klass.respond_to?(:env)
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
def
|
|
22
|
-
|
|
23
|
+
def paths
|
|
24
|
+
[
|
|
25
|
+
"./config/#{config_file_name}.yml",
|
|
26
|
+
"./config/#{config_file_name}.local.yml",
|
|
27
|
+
]
|
|
23
28
|
end
|
|
24
29
|
|
|
25
30
|
def config_file_name
|
|
26
31
|
klass.respond_to?(:config_file_name) ?
|
|
27
32
|
klass.config_file_name :
|
|
28
|
-
"#{klass.name.downcase.split("::").last}
|
|
33
|
+
"#{klass.name.downcase.split("::").last}"
|
|
29
34
|
end
|
|
30
35
|
|
|
31
|
-
def yaml_file
|
|
36
|
+
def yaml_file(path)
|
|
37
|
+
return {} unless File.exists?(path)
|
|
32
38
|
content = File.open(path).read
|
|
33
39
|
YAML.load(ERB.new(content).result)
|
|
34
40
|
end
|
data/lib/simple-conf/version.rb
CHANGED
data/spec/simple_conf_spec.rb
CHANGED
|
@@ -30,7 +30,7 @@ end
|
|
|
30
30
|
|
|
31
31
|
class SettingsWithFilename
|
|
32
32
|
def self.config_file_name
|
|
33
|
-
'settings
|
|
33
|
+
'settings'
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
include SimpleConf
|
|
@@ -38,41 +38,42 @@ end
|
|
|
38
38
|
|
|
39
39
|
describe SimpleConf do
|
|
40
40
|
context "on include to config class generate properties" do
|
|
41
|
-
it { Configuration.staging.domain.should
|
|
41
|
+
it { Configuration.staging.domain.should eq("staging.example.com") }
|
|
42
42
|
|
|
43
43
|
it "should work properly with collections" do
|
|
44
|
-
Configuration.staging.links.
|
|
44
|
+
expect(Configuration.staging.links).to eq([
|
|
45
45
|
"test1.example.com",
|
|
46
|
-
"test2.example.com"
|
|
47
|
-
]
|
|
46
|
+
"test2.example.com",
|
|
47
|
+
])
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
it { Configuration.production.domain.
|
|
50
|
+
it { expect(Configuration.production.domain).to eq("production.example.com") }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
context "on include to options class generate properties with only one key and value" do
|
|
54
|
-
it { Options.domain.
|
|
54
|
+
it { expect(Options.domain).to eq("example.com") }
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
describe SimpleConf do
|
|
59
59
|
context "on include properties depending on rails environment" do
|
|
60
|
-
it { Configuration.domain.
|
|
60
|
+
it { expect(Configuration.domain).to eq("staging.example.com") }
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
describe SimpleConf do
|
|
65
|
-
|
|
66
|
-
Settings.domain.
|
|
65
|
+
it 'on include properties depenending on env method' do
|
|
66
|
+
expect(Settings.domain).to eq('test.example.com')
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
class TestObject ; end
|
|
71
|
-
|
|
72
70
|
describe SimpleConf do
|
|
71
|
+
class TestObject ; end
|
|
72
|
+
|
|
73
73
|
before do
|
|
74
|
+
File.stub(:exists?).and_return(true)
|
|
74
75
|
file = double('file', :read => attrib('test').to_yaml)
|
|
75
|
-
File.stub
|
|
76
|
+
File.stub(:open).and_return(file)
|
|
76
77
|
end
|
|
77
78
|
|
|
78
79
|
context "when we have env params in the configuration file" do
|
|
@@ -86,11 +87,11 @@ describe SimpleConf do
|
|
|
86
87
|
before { loader.run }
|
|
87
88
|
|
|
88
89
|
it "should return username" do
|
|
89
|
-
TestObject.test.username.
|
|
90
|
+
expect(TestObject.test.username).to eq('fred')
|
|
90
91
|
end
|
|
91
92
|
|
|
92
93
|
it "should return password fetched from the environment" do
|
|
93
|
-
TestObject.test.password.
|
|
94
|
+
expect(TestObject.test.password).to eq('password')
|
|
94
95
|
end
|
|
95
96
|
end
|
|
96
97
|
end
|
|
@@ -107,7 +108,18 @@ end
|
|
|
107
108
|
|
|
108
109
|
describe SimpleConf do
|
|
109
110
|
it 'should be possible to use defined name in the settings class for loading the configuration file' do
|
|
110
|
-
SettingsWithFilename.test.domain.
|
|
111
|
+
expect(SettingsWithFilename.test.domain).to eq('test.example.com')
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
class Options2
|
|
116
|
+
include SimpleConf
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe SimpleConf do
|
|
120
|
+
it 'supports .local.yml file for loading extra options' do
|
|
121
|
+
expect(Options2).to respond_to(:group1)
|
|
122
|
+
expect(Options2).to respond_to(:group2)
|
|
111
123
|
end
|
|
112
124
|
end
|
|
113
125
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -4,3 +4,11 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
4
4
|
require 'rubygems'
|
|
5
5
|
require 'simple-conf'
|
|
6
6
|
|
|
7
|
+
RSpec.configure do |config|
|
|
8
|
+
require 'rspec/expectations'
|
|
9
|
+
config.include RSpec::Matchers
|
|
10
|
+
|
|
11
|
+
config.mock_with :rspec
|
|
12
|
+
|
|
13
|
+
config.backtrace_exclusion_patterns = [%r{lib\/rspec\/(core|expectations|matchers|mocks)}]
|
|
14
|
+
end
|
metadata
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple-conf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.2.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Alexander Korsak
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: rake
|
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
16
|
requirements:
|
|
19
17
|
- - ! '>='
|
|
20
18
|
- !ruby/object:Gem::Version
|
|
@@ -22,7 +20,6 @@ dependencies:
|
|
|
22
20
|
type: :runtime
|
|
23
21
|
prerelease: false
|
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
23
|
requirements:
|
|
27
24
|
- - ! '>='
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
@@ -38,6 +35,7 @@ files:
|
|
|
38
35
|
- .gitignore
|
|
39
36
|
- .rspec
|
|
40
37
|
- .rvmrc
|
|
38
|
+
- .vimrc
|
|
41
39
|
- Gemfile
|
|
42
40
|
- Guardfile
|
|
43
41
|
- LICENSE
|
|
@@ -45,6 +43,8 @@ files:
|
|
|
45
43
|
- Rakefile
|
|
46
44
|
- config/configuration.yml
|
|
47
45
|
- config/options.yml
|
|
46
|
+
- config/options2.local.yml
|
|
47
|
+
- config/options2.yml
|
|
48
48
|
- config/settings.yml
|
|
49
49
|
- lib/simple-conf.rb
|
|
50
50
|
- lib/simple-conf/loader.rb
|
|
@@ -55,33 +55,26 @@ files:
|
|
|
55
55
|
homepage: http://github.com/oivoodoo/simple-conf/
|
|
56
56
|
licenses:
|
|
57
57
|
- MIT
|
|
58
|
+
metadata: {}
|
|
58
59
|
post_install_message:
|
|
59
60
|
rdoc_options: []
|
|
60
61
|
require_paths:
|
|
61
62
|
- lib
|
|
62
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
-
none: false
|
|
64
64
|
requirements:
|
|
65
65
|
- - ! '>='
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '0'
|
|
68
|
-
segments:
|
|
69
|
-
- 0
|
|
70
|
-
hash: -847311465064856186
|
|
71
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
|
-
none: false
|
|
73
69
|
requirements:
|
|
74
70
|
- - ! '>='
|
|
75
71
|
- !ruby/object:Gem::Version
|
|
76
72
|
version: '0'
|
|
77
|
-
segments:
|
|
78
|
-
- 0
|
|
79
|
-
hash: -847311465064856186
|
|
80
73
|
requirements: []
|
|
81
74
|
rubyforge_project:
|
|
82
|
-
rubygems_version: 1.
|
|
75
|
+
rubygems_version: 2.1.11
|
|
83
76
|
signing_key:
|
|
84
|
-
specification_version:
|
|
77
|
+
specification_version: 4
|
|
85
78
|
summary: Simple configuration library for yml files for loading from the config folder
|
|
86
79
|
test_files:
|
|
87
80
|
- spec/simple_conf_spec.rb
|