midwire_common 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +1 -1
- data/lib/midwire_common/all.rb +1 -0
- data/lib/midwire_common/version.rb +1 -1
- data/lib/midwire_common/yaml_setting.rb +31 -0
- data/spec/lib/midwire_common/yaml_setting_spec.rb +45 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 201f582c20efc16375b3297a699483c99bf5bb14
|
4
|
+
data.tar.gz: 00296b47a26d4dd563114f9ece99c56a832da405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba407480b9c285c83f12c4fc3a4591d93c44508843c4640c699e531aa5b32f7b5cbced37136a66a6fe60a57076a1b07d38eaf98deffac82a0213b17e51d87b0e
|
7
|
+
data.tar.gz: a6eb11f467f4d2966ba1bb11574e3dc136c4de50b4ad18c206204c85c81b202069d54b0a03f6cddf9682af54f87fc84c2d7755308f6dfa9dd2750f1fe9517ea4
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
data/lib/midwire_common/all.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module MidwireCommon
|
4
|
+
class YamlSetting
|
5
|
+
attr_accessor :file
|
6
|
+
|
7
|
+
def initialize(file)
|
8
|
+
@file = file
|
9
|
+
end
|
10
|
+
|
11
|
+
def load
|
12
|
+
@config ||= YAML.load_file(file) || {}
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def save
|
17
|
+
File.open(file, 'w') { |f| f.write(YAML.dump(@config)) }
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](key)
|
22
|
+
load
|
23
|
+
@config[key]
|
24
|
+
end
|
25
|
+
|
26
|
+
def []=(key, value)
|
27
|
+
load
|
28
|
+
@config[key] = value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MidwireCommon::YamlSetting do
|
4
|
+
let(:root) { Pathname.new(File.dirname(__FILE__)).parent.parent.parent }
|
5
|
+
let(:tmpdir) { File.join(root, 'tmp') }
|
6
|
+
let(:file) { File.join(tmpdir, 'bogus.yml') }
|
7
|
+
let(:setting) { YamlSetting.new(file) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
FileUtils.touch(file)
|
11
|
+
setting[:test] = {}
|
12
|
+
setting[:test][:a] = 1
|
13
|
+
setting[:test][:b] = 2
|
14
|
+
setting[:test][:c] = 3
|
15
|
+
setting.save
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#new' do
|
19
|
+
it 'sets the :file accessor' do
|
20
|
+
expect(setting.file).to eq(file)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '.load' do
|
25
|
+
it 'returns self' do
|
26
|
+
expect(setting.load).to be_a(YamlSetting)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'loads the YAML' do
|
30
|
+
setting.load
|
31
|
+
expect(setting[:test]).to be_a(Hash)
|
32
|
+
expect(setting[:test][:a]).to eq(1)
|
33
|
+
expect(setting[:test][:b]).to eq(2)
|
34
|
+
expect(setting[:test][:c]).to eq(3)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context '.save' do
|
39
|
+
it 'stores the current hash' do
|
40
|
+
setting[:test] = 'bogus'
|
41
|
+
setting.save
|
42
|
+
expect(setting[:test]).to eq('bogus')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midwire_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Blackburn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- lib/midwire_common/time.rb
|
170
170
|
- lib/midwire_common/time_tool.rb
|
171
171
|
- lib/midwire_common/version.rb
|
172
|
+
- lib/midwire_common/yaml_setting.rb
|
172
173
|
- lib/tasks/version.rake
|
173
174
|
- midwire_common.gemspec
|
174
175
|
- spec/lib/midwire_common/array_spec.rb
|
@@ -181,6 +182,7 @@ files:
|
|
181
182
|
- spec/lib/midwire_common/string_spec.rb
|
182
183
|
- spec/lib/midwire_common/time_spec.rb
|
183
184
|
- spec/lib/midwire_common/time_tool_spec.rb
|
185
|
+
- spec/lib/midwire_common/yaml_setting_spec.rb
|
184
186
|
- spec/spec_helper.rb
|
185
187
|
homepage: https://github.com/midwire/midwire_common
|
186
188
|
licenses: []
|
@@ -216,4 +218,5 @@ test_files:
|
|
216
218
|
- spec/lib/midwire_common/string_spec.rb
|
217
219
|
- spec/lib/midwire_common/time_spec.rb
|
218
220
|
- spec/lib/midwire_common/time_tool_spec.rb
|
221
|
+
- spec/lib/midwire_common/yaml_setting_spec.rb
|
219
222
|
- spec/spec_helper.rb
|