app_conf 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
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.6'
5
+ s.version = '0.2.7'
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
@@ -14,9 +14,19 @@ class AppConf
14
14
  end
15
15
 
16
16
  def self.save(key, filename)
17
+
18
+
17
19
  mode = File.exist?(filename) ? 'r+' : 'w+'
18
20
  File.open(filename, mode) do |f|
19
- while f.readline =~ /^#/; end unless f.eof?
21
+ unless f.eof?
22
+ begin
23
+ pos = f.pos
24
+ line = f.readline
25
+ rescue
26
+ raise YAML::ParseError, 'No document start (---) found.'
27
+ end until line =~ /^---/
28
+ f.seek(pos)
29
+ end
20
30
  hash = {key.to_s => @@root[key].to_hash}
21
31
  YAML.dump(hash, f)
22
32
  f.truncate(f.pos)
@@ -40,10 +40,15 @@ user:
40
40
  end
41
41
 
42
42
  it 'skips past comments' do
43
- File.open('config.yml', 'w') {|f| f.write("# comment 1\n# comment 2\n\nRest of the config")}
43
+ File.open('config.yml', 'w') {|f| f.write("# comment 1\n# comment 2\n\n--- \nRest of the config")}
44
44
  AppConf.save :user, 'config.yml'
45
45
  File.read('config.yml').must_equal "# comment 1\n# comment 2\n\n--- \nuser: \n name: \n first: Joe\n"
46
46
  end
47
+
48
+ it 'fails when no ---' do
49
+ File.open('config.yml', 'w') {|f| f.write('some config') }
50
+ lambda {AppConf.save :user, 'config.yml'}.must_raise YAML::ParseError
51
+ end
47
52
  end
48
53
 
49
54
  describe 'to_hash' do
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.6
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-14 00:00:00.000000000Z
12
+ date: 2011-12-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fakefs
16
- requirement: &22432300 !ruby/object:Gem::Requirement
16
+ requirement: &9586880 !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: *22432300
24
+ version_requirements: *9586880
25
25
  description:
26
26
  email: phil@electricvisions.com
27
27
  executables: []