midwire_common 0.1.14 → 0.1.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c287f516c96b86ffed9811bf83345e6ea81fd37
4
- data.tar.gz: 2ed25b685f28130a5bbd482e2ca76024ab3900f0
3
+ metadata.gz: 201f582c20efc16375b3297a699483c99bf5bb14
4
+ data.tar.gz: 00296b47a26d4dd563114f9ece99c56a832da405
5
5
  SHA512:
6
- metadata.gz: 8739b57f7ed6d11fdeb8165341d8e65e2f9cd1634cabb1d34fc7c5925a82ce35d56dacd7d48f3c8230d13c4366feabddd7d7be7de16f1e2e8e663a2306e2bba9
7
- data.tar.gz: 229cdfb424c9efdb49000cf67e3e4f2cc8c22cb8a35ba72fe24a4d4a8a87851b257c0ae3af7aefeb7a88c4592cfc0005431f71e24aa435b2423a64a714fc6658
6
+ metadata.gz: ba407480b9c285c83f12c4fc3a4591d93c44508843c4640c699e531aa5b32f7b5cbced37136a66a6fe60a57076a1b07d38eaf98deffac82a0213b17e51d87b0e
7
+ data.tar.gz: a6eb11f467f4d2966ba1bb11574e3dc136c4de50b4ad18c206204c85c81b202069d54b0a03f6cddf9682af54f87fc84c2d7755308f6dfa9dd2750f1fe9517ea4
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.1.15* (March 08, 2015)
2
+
3
+ * Add YamlSetting class
4
+
1
5
  *0.1.14* (March 03, 2015)
2
6
 
3
7
  * Require 'string' for rake task
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Midwire Common Gem
2
2
 
3
- **Version: 0.1.14**
3
+ **Version: 0.1.15**
4
4
 
5
5
  A handy Ruby library for Midwire development
6
6
 
@@ -9,3 +9,4 @@ require 'midwire_common/string'
9
9
  # require 'midwire_common/system_command'
10
10
  require 'midwire_common/time'
11
11
  require 'midwire_common/time_tool'
12
+ require 'midwire_common/yaml_setting'
@@ -1,6 +1,6 @@
1
1
  original_verbosity = $VERBOSE
2
2
  $VERBOSE = nil
3
3
  module MidwireCommon
4
- VERSION = "0.1.14"
4
+ VERSION = "0.1.15"
5
5
  end
6
6
  $VERBOSE = original_verbosity
@@ -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.14
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-03 00:00:00.000000000 Z
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