konf 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/konf.gemspec +3 -2
- data/lib/konf.rb +7 -2
- data/test/blank_config.yml +0 -0
- data/test/konf_test.rb +10 -8
- metadata +8 -7
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/konf.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "konf"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Oleg Khabarov"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2012-01-23"
|
13
13
|
s.description = "minimalistic configuration reader"
|
14
14
|
s.email = "oleg@khabarov.ca"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
"VERSION",
|
25
25
|
"konf.gemspec",
|
26
26
|
"lib/konf.rb",
|
27
|
+
"test/blank_config.yml",
|
27
28
|
"test/config.yml",
|
28
29
|
"test/konf_test.rb"
|
29
30
|
]
|
data/lib/konf.rb
CHANGED
@@ -2,14 +2,19 @@ require 'yaml'
|
|
2
2
|
require 'erb'
|
3
3
|
|
4
4
|
class Konf < Hash
|
5
|
-
class NotFound
|
5
|
+
class NotFound < StandardError; end
|
6
|
+
class Invalid < StandardError; end
|
6
7
|
|
7
8
|
def initialize(source, root = nil)
|
8
9
|
hash = case source
|
9
10
|
when Hash
|
10
11
|
source
|
11
12
|
else
|
12
|
-
YAML.load(ERB.new(File.read(source)).result)
|
13
|
+
if File.exists?(source.to_s) && yaml = YAML.load(ERB.new(File.read(source.to_s)).result)
|
14
|
+
yaml.to_hash
|
15
|
+
else
|
16
|
+
raise Invalid, "Invalid configuration input: #{source}"
|
17
|
+
end
|
13
18
|
end
|
14
19
|
if root
|
15
20
|
hash = hash[root] or raise NotFound, "No configuration found for '#{root}'"
|
File without changes
|
data/test/konf_test.rb
CHANGED
@@ -21,6 +21,16 @@ class KonfTest < Test::Unit::TestCase
|
|
21
21
|
}), conf
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_initialization_as_invalid
|
25
|
+
[nil, 99, 'invalid.yml', File.expand_path('blank_config.yml', File.dirname(__FILE__))].each do |source|
|
26
|
+
begin
|
27
|
+
Konf.new(source)
|
28
|
+
rescue => e
|
29
|
+
assert_equal Konf::Invalid, e.class, e.inspect
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
def test_initialization_with_root
|
25
35
|
conf = Konf.new({'a' => {'b' => 'c'}}, 'a')
|
26
36
|
assert_equal ({'b' => 'c'}), conf
|
@@ -34,14 +44,6 @@ class KonfTest < Test::Unit::TestCase
|
|
34
44
|
end
|
35
45
|
end
|
36
46
|
|
37
|
-
def test_initialization_with_invalid_file
|
38
|
-
begin
|
39
|
-
conf = Konf.new('invalid')
|
40
|
-
rescue => e
|
41
|
-
assert_equal Errno::ENOENT, e.class
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
47
|
def test_initialization_with_invalid_root
|
46
48
|
begin
|
47
49
|
conf = Konf.new({'a' => {'b' => 'c'}}, 'd')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: konf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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:
|
12
|
+
date: 2012-01-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &70276412593660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70276412593660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jeweler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70276412593040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 1.6.4
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70276412593040
|
36
36
|
description: minimalistic configuration reader
|
37
37
|
email: oleg@khabarov.ca
|
38
38
|
executables: []
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- VERSION
|
49
49
|
- konf.gemspec
|
50
50
|
- lib/konf.rb
|
51
|
+
- test/blank_config.yml
|
51
52
|
- test/config.yml
|
52
53
|
- test/konf_test.rb
|
53
54
|
homepage: http://github.com/GBH/konf
|
@@ -65,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
66
|
version: '0'
|
66
67
|
segments:
|
67
68
|
- 0
|
68
|
-
hash:
|
69
|
+
hash: 2443533440992825314
|
69
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
71
|
none: false
|
71
72
|
requirements:
|