yamlconfig 0.1.1 → 0.1.2

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.
@@ -1,4 +1,4 @@
1
- # $Id: yamlconfig.rb 46 2006-08-14 06:13:47Z cmaujean $
1
+ # $Id: yamlconfig.rb 67 2006-08-30 15:54:59Z erikh $
2
2
  #
3
3
  # See LICENSE for copyright information
4
4
  #
@@ -74,9 +74,12 @@ class YAMLConfig
74
74
  # named in @resource into psuedo attr_readers
75
75
  def reload
76
76
  # first remove all the previous methods from this instance
77
- @specialmethods.each do |meth|
78
- (class << self; self; end).class_eval { undef_method(meth) }
79
- end
77
+
78
+ if @specialmethods
79
+ @specialmethods.each do |meth|
80
+ (class << self; self; end).class_eval { undef_method(meth) }
81
+ end
82
+ end
80
83
 
81
84
  # wipe the old list
82
85
  @specialmethods = []
@@ -86,14 +89,14 @@ class YAMLConfig
86
89
  # giving a private readonly accessor named "key" that returns "value" for each
87
90
  # key value pair of the YAML file named in @filename
88
91
  @con = loadresource()
89
- @con.each do |key,value|
90
- (class << self; self; end).class_eval { define_method(key) { value }}
91
-
92
- #add it to the @specialmethods array
93
- @specialmethods.push key
94
- end
95
-
96
-
92
+ if @con
93
+ @con.each do |key,value|
94
+ (class << self; self; end).class_eval { define_method(key) { value }}
95
+
96
+ #add it to the @specialmethods array
97
+ @specialmethods.push key
98
+ end
99
+ end
97
100
  end
98
101
 
99
102
  # standard each usage, iterates over the config keys
@@ -112,8 +115,10 @@ class YAMLConfig
112
115
  def loadresource()
113
116
  # TODO, make this take plugins or some sort of adapter type scheme for
114
117
  # deciding how to load what into a hash
115
- YAML.load_file(@resource)
118
+ YAML.load_file(@resource) || { }
116
119
  end
117
120
  end
118
121
 
122
+ require 'yamlconfig/version'
123
+
119
124
  # vi:sw=2 ts=2
@@ -0,0 +1 @@
1
+ YAMLConfig::VERSION = "0.1.2"
@@ -0,0 +1,2 @@
1
+ arrayval: [ foo, bar, baz ]
2
+ hashval: { foo: FOO , bar: BAR }
File without changes
@@ -3,6 +3,18 @@ require 'yamlconfig'
3
3
  require 'fileutils'
4
4
 
5
5
  class TestConfig < Test::Unit::TestCase
6
+ def test_yaml_empty
7
+ assert_nothing_raised do
8
+ YAMLConfig.new('yamlconfig/test/data/empty_file')
9
+ end
10
+ end
11
+
12
+ def test_yaml_complex
13
+ f = YAMLConfig.new('yamlconfig/test/data/complex_values')
14
+ assert_equal(f.arrayval[1], "bar", "array values work")
15
+ assert_equal(f.hashval["foo"], "FOO", "hash values work")
16
+ end
17
+
6
18
  def test_yaml_write
7
19
  old_file = 'yamlconfig/test/data/accessor_config'
8
20
  new_file = old_file + '_tmp'
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: yamlconfig
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2006-08-13 00:00:00 -07:00
6
+ version: 0.1.2
7
+ date: 2007-09-16 00:00:00 -07:00
8
8
  summary: YAML file based configuration object with an EASY interface
9
9
  require_paths:
10
10
  - lib
@@ -30,13 +30,17 @@ authors:
30
30
  - Christopher Maujean
31
31
  files:
32
32
  - lib/LICENSE
33
+ - lib/yamlconfig
34
+ - lib/yamlconfig/version.rb
33
35
  - lib/yamlconfig.rb
34
36
  - test/data
35
- - test/tc_yamlconfig.rb
37
+ - test/data/accessor_config
38
+ - test/data/complex_values
36
39
  - test/data/config
37
- - test/data/freakboy
40
+ - test/data/empty_file
38
41
  - test/data/flatulentmonkey
39
- - test/data/accessor_config
42
+ - test/data/freakboy
43
+ - test/tc_yamlconfig.rb
40
44
  test_files:
41
45
  - test/tc_yamlconfig.rb
42
46
  rdoc_options: []