app_conf 0.2.9 → 0.3.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.
data/app_conf.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'base64'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'app_conf'
5
- s.version = '0.2.9'
5
+ s.version = '0.3.0'
6
6
  s.authors = 'Phil Thompson'
7
7
  s.email = Base64.decode64("cGhpbEBlbGVjdHJpY3Zpc2lvbnMuY29t\n")
8
8
  s.summary = 'Simplest YAML Backed Application Wide Configuration (AppConfig)'
data/lib/app_conf.rb CHANGED
@@ -21,7 +21,7 @@ class AppConf
21
21
  pos = f.pos
22
22
  line = f.readline
23
23
  end until line =~ /^---/ || f.eof?
24
- f.seek(pos)
24
+ line =~ /^---/ ? f.seek(pos) : f.rewind
25
25
  end
26
26
  hash = {key.to_s => @@root[key].to_hash}
27
27
  YAML.dump(hash, f)
@@ -29,11 +29,15 @@ class AppConf
29
29
  end
30
30
  end
31
31
 
32
- def self.clear
33
- @@root = new
32
+ def self.clear key = nil
33
+ key ? @@root.clear(key) : @@root = new
34
34
  nil
35
35
  end
36
36
 
37
+ def clear key
38
+ @hash[key.to_s] = nil
39
+ end
40
+
37
41
  def self.to_hash
38
42
  @@root.to_hash
39
43
  end
@@ -33,6 +33,22 @@ user:
33
33
  AppConf.user.must_be_nil
34
34
  end
35
35
 
36
+ it 'clears a key' do
37
+ AppConf.user.clear :name
38
+ AppConf.user.name.must_be_nil
39
+ end
40
+
41
+ it 'clears a key in root' do
42
+ AppConf.clear :user
43
+ AppConf.user.must_be_nil
44
+ end
45
+
46
+ it 'cleared key can be overwritten' do
47
+ AppConf.clear :user
48
+ AppConf.user = 'something'
49
+ AppConf.user.must_equal 'something'
50
+ end
51
+
36
52
  describe 'save' do
37
53
  it 'saves a key and children to yml' do
38
54
  AppConf.save :user, 'temp.yml'
@@ -45,8 +61,14 @@ user:
45
61
  File.read('config.yml').must_equal "# comment 1\n# comment 2\n\n--- \nuser: \n name: \n first: Joe\n"
46
62
  end
47
63
 
48
- it 'overwrites when no ---' do
49
- File.open('config.yml', 'w') {|f| f.write('some config') }
64
+ it 'overwrites when no --- and single line' do
65
+ File.open('config.yml', 'w') {|f| f.write("some config\n") }
66
+ AppConf.save :user, 'config.yml'
67
+ File.read('config.yml').must_equal "--- \nuser: \n name: \n first: Joe\n"
68
+ end
69
+
70
+ it 'overwrites when no --- and multiline' do
71
+ File.open('config.yml', 'w') {|f| f.write("# Some\n# comments\n\nconfig:\n name:\n") }
50
72
  AppConf.save :user, 'config.yml'
51
73
  File.read('config.yml').must_equal "--- \nuser: \n name: \n first: Joe\n"
52
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_conf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fakefs
16
- requirement: &23498740 !ruby/object:Gem::Requirement
16
+ requirement: &9210480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *23498740
24
+ version_requirements: *9210480
25
25
  description:
26
26
  email: phil@electricvisions.com
27
27
  executables: []