parseconfig 0.4.2 → 0.4.3
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/Changelog +4 -0
- data/demo.conf +1 -0
- data/demo.rb +16 -4
- data/lib/parseconfig.rb +15 -12
- metadata +2 -2
data/Changelog
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
Sat Mar 28, 2009 - v0.4.3
|
2
|
+
- Added the self.params member that is a Hash holding all parameter/values.
|
3
|
+
- Added the 'get_params' to return an array of all config parameters.
|
4
|
+
|
1
5
|
Thu Feb 28, 2008 - v0.4.2
|
2
6
|
- Fixed bug where if the value contains a '=' then the parameter
|
3
7
|
is not properly set. [bjd]
|
data/demo.conf
CHANGED
data/demo.rb
CHANGED
@@ -5,7 +5,7 @@ require('parseconfig')
|
|
5
5
|
#require('./lib/parseconfig.rb')
|
6
6
|
|
7
7
|
begin
|
8
|
-
|
8
|
+
c = ParseConfig.new('demo.conf')
|
9
9
|
rescue Errno::ENOENT
|
10
10
|
puts "The config file you specified was not found"
|
11
11
|
exit
|
@@ -14,7 +14,19 @@ rescue Errno::EACCES
|
|
14
14
|
exit
|
15
15
|
end
|
16
16
|
|
17
|
-
puts "Hello, my name is #{
|
18
|
-
puts "I am #{
|
19
|
-
puts "I currently live at #{
|
17
|
+
puts "Hello, my name is #{c.get_value('name')}."
|
18
|
+
puts "I am #{c.get_value('age')} years old, but will be #{c.override_value('age', '22')} soon."
|
19
|
+
puts "I currently live at #{c.params['address']}, and my slogan is \"#{c.get_value('slogan')}\"."
|
20
20
|
|
21
|
+
puts
|
22
|
+
puts
|
23
|
+
puts "All the paramaters are..."
|
24
|
+
res = c.get_params()
|
25
|
+
res.each do |param|
|
26
|
+
puts param
|
27
|
+
end
|
28
|
+
|
29
|
+
puts
|
30
|
+
puts
|
31
|
+
puts "using params hash"
|
32
|
+
puts c.params['age']
|
data/lib/parseconfig.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# $Id: parseconfig.rb
|
2
|
+
# $Id: parseconfig.rb 37 2008-02-29 07:27:33Z wdierkes $
|
3
3
|
#
|
4
4
|
# Author:: BJ Dierkes <wdierkes@5dollarwhitebox.org>
|
5
5
|
# Copyright:: Copyright (c) 2006,2007 5dollarwhitebox.org
|
@@ -17,7 +17,9 @@
|
|
17
17
|
|
18
18
|
class ParseConfig
|
19
19
|
|
20
|
-
Version = '0.4.
|
20
|
+
Version = '0.4.3'
|
21
|
+
|
22
|
+
attr_accessor :config_file, :params
|
21
23
|
|
22
24
|
# Initialize the class with the path to the 'config_file'
|
23
25
|
# The class objects are dynamically generated by the
|
@@ -27,9 +29,13 @@ class ParseConfig
|
|
27
29
|
#
|
28
30
|
def initialize(config_file)
|
29
31
|
@config_file = config_file
|
30
|
-
|
32
|
+
@params = {}
|
33
|
+
if !File.readable?(self.config_file)
|
34
|
+
raise Errno::EACCES, "#{self.config_file} is not readable"
|
35
|
+
end
|
36
|
+
|
31
37
|
open(self.config_file).each { |line|
|
32
|
-
line.
|
38
|
+
line.strip!
|
33
39
|
unless (/^\#/.match(line))
|
34
40
|
if(/\s*=\s*/.match(line))
|
35
41
|
param, value = line.split(/\s*=\s*/, 2)
|
@@ -46,6 +52,7 @@ class ParseConfig
|
|
46
52
|
new_value = ''
|
47
53
|
end
|
48
54
|
self.instance_variable_set("@#{var_name}", new_value)
|
55
|
+
self.params["#{var_name}"] = new_value
|
49
56
|
end
|
50
57
|
end
|
51
58
|
}
|
@@ -71,13 +78,9 @@ class ParseConfig
|
|
71
78
|
def nil_value(param)
|
72
79
|
self.instance_variable_set("@#{param}", nil)
|
73
80
|
end
|
74
|
-
|
75
|
-
def
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
def config_file()
|
80
|
-
@config_file
|
81
|
+
|
82
|
+
def get_params()
|
83
|
+
return self.params.keys
|
81
84
|
end
|
82
|
-
|
85
|
+
|
83
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parseconfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BJ Dierkes
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-03-28 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|