rclconf 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/InstalledFiles +4 -0
- data/LICENSE.txt +339 -0
- data/Manifest.txt +12 -0
- data/README.txt +45 -0
- data/Rakefile +28 -0
- data/config.save +12 -0
- data/lib/rclconf.rb +8 -0
- data/lib/rclconf/rclconf.rb +65 -0
- data/rclconf.gemspec +20 -0
- data/setup.rb +1345 -0
- data/test/test_rclconf.rb +161 -0
- metadata +103 -0
@@ -0,0 +1,161 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# RCLConfTest -- rclconf -- 19.01.2005 -- hwyss@ywesee.com, rwaltert@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'rclconf/rclconf'
|
8
|
+
require 'fileutils'
|
9
|
+
|
10
|
+
module RCLConf
|
11
|
+
class RCLConfTest < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
argv = [
|
14
|
+
'foo=bar',
|
15
|
+
'fx=baz',
|
16
|
+
'override_default=override',
|
17
|
+
'overfalse=false',
|
18
|
+
]
|
19
|
+
defaults = {
|
20
|
+
"dir" => "home",
|
21
|
+
'override_default' => 'original',
|
22
|
+
'overfalse' => true,
|
23
|
+
'nested' => {'foo' => 'F'}
|
24
|
+
}
|
25
|
+
@conf = RCLConf.new(argv, defaults)
|
26
|
+
@datadir = File.expand_path('data', File.dirname(__FILE__))
|
27
|
+
end
|
28
|
+
def teardown
|
29
|
+
FileUtils.rm_r(@datadir) if(File.exist?(@datadir))
|
30
|
+
end
|
31
|
+
def test_argv
|
32
|
+
assert_equal('bar', @conf.foo)
|
33
|
+
assert_equal('baz', @conf.fx)
|
34
|
+
end
|
35
|
+
def test_argv_overrides_defaults
|
36
|
+
assert_equal('override', @conf.override_default)
|
37
|
+
end
|
38
|
+
def test_argv__false__overrides_defaults
|
39
|
+
assert_equal(false, @conf.overfalse)
|
40
|
+
end
|
41
|
+
def test_argv_overrides_file
|
42
|
+
FileUtils.mkdir_p(@datadir)
|
43
|
+
filepath = File.join(@datadir, 'config.yaml')
|
44
|
+
file_data = {
|
45
|
+
'foo' => 'baz'
|
46
|
+
}
|
47
|
+
File.open(filepath, 'w') { |fh|
|
48
|
+
YAML.dump(file_data, fh)
|
49
|
+
}
|
50
|
+
@conf.load(filepath)
|
51
|
+
assert_equal('bar', @conf.foo)
|
52
|
+
end
|
53
|
+
def test_file_overrides_defaults
|
54
|
+
FileUtils.mkdir_p(@datadir)
|
55
|
+
filepath = File.join(@datadir, 'config.yaml')
|
56
|
+
file_data = {
|
57
|
+
'dir' => 'baz'
|
58
|
+
}
|
59
|
+
File.open(filepath, 'w') { |fh|
|
60
|
+
YAML.dump(file_data, fh)
|
61
|
+
}
|
62
|
+
@conf.load(filepath)
|
63
|
+
assert_equal('baz', @conf.dir)
|
64
|
+
end
|
65
|
+
def test_defaults
|
66
|
+
assert_equal('home', @conf.dir)
|
67
|
+
end
|
68
|
+
def test_load_mandatory__no_file__raises_error
|
69
|
+
assert_raises(Errno::ENOENT) {
|
70
|
+
@conf.load('/no/such/file.yaml')
|
71
|
+
}
|
72
|
+
end
|
73
|
+
def test_load_mandatory__file_found
|
74
|
+
FileUtils.mkdir_p(@datadir)
|
75
|
+
filepath = File.join(@datadir, 'config.yaml')
|
76
|
+
file_data = {
|
77
|
+
'file_loaded' => 'success'
|
78
|
+
}
|
79
|
+
File.open(filepath, 'w') { |fh|
|
80
|
+
YAML.dump(file_data, fh)
|
81
|
+
}
|
82
|
+
assert_nothing_raised {
|
83
|
+
@conf.load(filepath)
|
84
|
+
}
|
85
|
+
assert_equal('success', @conf.file_loaded)
|
86
|
+
end
|
87
|
+
def test_load_optional__no_file__no_error
|
88
|
+
assert_nothing_raised {
|
89
|
+
@conf.load(['/no/such/file.yaml'])
|
90
|
+
}
|
91
|
+
assert_nothing_raised {
|
92
|
+
@conf.foo
|
93
|
+
}
|
94
|
+
end
|
95
|
+
def test_load_optional__file_precedence
|
96
|
+
FileUtils.mkdir_p(@datadir)
|
97
|
+
filepath = File.join(@datadir, 'config.yaml')
|
98
|
+
otherpath = File.join(@datadir, 'not_loaded.yaml')
|
99
|
+
file_data = {
|
100
|
+
'file_loaded' => 'success',
|
101
|
+
}
|
102
|
+
other_data = {
|
103
|
+
'file_loaded' => 'twice',
|
104
|
+
'undefined' => 'defined!?'
|
105
|
+
}
|
106
|
+
File.open(filepath, 'w') { |fh|
|
107
|
+
YAML.dump(file_data, fh)
|
108
|
+
}
|
109
|
+
File.open(otherpath, 'w') { |fh|
|
110
|
+
YAML.dump(other_data, fh)
|
111
|
+
}
|
112
|
+
assert_nothing_raised {
|
113
|
+
@conf.load(['/no/such/file.yaml', filepath, otherpath])
|
114
|
+
}
|
115
|
+
assert_equal('success', @conf.file_loaded)
|
116
|
+
## check that the second file was _not_ loaded
|
117
|
+
assert_raises(NoMethodError) { @conf.undefined }
|
118
|
+
end
|
119
|
+
def test_no_method_error
|
120
|
+
assert_raises(NoMethodError) { @conf.undefined_method }
|
121
|
+
end
|
122
|
+
def test_parse_argv
|
123
|
+
data = [
|
124
|
+
'foo=bar',
|
125
|
+
'fx=baz',
|
126
|
+
'mux=zehn=mal=weiter',
|
127
|
+
]
|
128
|
+
expected = {
|
129
|
+
'foo' => 'bar',
|
130
|
+
'fx' => 'baz',
|
131
|
+
'mux' => 'zehn=mal=weiter',
|
132
|
+
}
|
133
|
+
assert_equal(expected, @conf.parse_argv(data))
|
134
|
+
end
|
135
|
+
def test_parse_argv__keywords
|
136
|
+
data = [
|
137
|
+
'foo=false',
|
138
|
+
'bar=nil',
|
139
|
+
'baz=true',
|
140
|
+
]
|
141
|
+
expected = {
|
142
|
+
'foo' => false,
|
143
|
+
'bar' => nil,
|
144
|
+
'baz' => true,
|
145
|
+
}
|
146
|
+
assert_equal(expected, @conf.parse_argv(data))
|
147
|
+
end
|
148
|
+
def test_respond_to
|
149
|
+
assert_respond_to(@conf, :foo)
|
150
|
+
assert_respond_to(@conf, :fx)
|
151
|
+
assert_respond_to(@conf, :dir)
|
152
|
+
assert_respond_to(@conf, :nested)
|
153
|
+
assert_respond_to(@conf, :foo=)
|
154
|
+
assert_respond_to(@conf, :bar=)
|
155
|
+
end
|
156
|
+
def test_runtime_overrides_argv
|
157
|
+
@conf.override_default = 'runtime'
|
158
|
+
assert_equal('runtime', @conf.override_default)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rclconf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Masaomi Hatakeyama, Zeno R.R. Davatz
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-16 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: hoe
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 47
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 8
|
33
|
+
- 0
|
34
|
+
version: 2.8.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: |-
|
38
|
+
rclconf is a pure Ruby library which is available for the configurtion
|
39
|
+
of a Ruby application.
|
40
|
+
|
41
|
+
rclconf manages yaml type of configuration files and has useful functions
|
42
|
+
to utilize commandline options.
|
43
|
+
email:
|
44
|
+
- mhatakeyama@ywesee.com, zdavatz@ywesee.com
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
extra_rdoc_files:
|
50
|
+
- History.txt
|
51
|
+
- LICENSE.txt
|
52
|
+
- Manifest.txt
|
53
|
+
- README.txt
|
54
|
+
files:
|
55
|
+
- History.txt
|
56
|
+
- InstalledFiles
|
57
|
+
- LICENSE.txt
|
58
|
+
- Manifest.txt
|
59
|
+
- README.txt
|
60
|
+
- Rakefile
|
61
|
+
- config.save
|
62
|
+
- lib/rclconf.rb
|
63
|
+
- lib/rclconf/rclconf.rb
|
64
|
+
- rclconf.gemspec
|
65
|
+
- setup.rb
|
66
|
+
- test/test_rclconf.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://scm.ywesee.com/?p=rclconf/.git;a=summary
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --main
|
74
|
+
- README.txt
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project: rclconf
|
98
|
+
rubygems_version: 1.3.7
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: rclconf is a pure Ruby library which is available for the configurtion of a Ruby application
|
102
|
+
test_files:
|
103
|
+
- test/test_rclconf.rb
|