emissary 1.3.21 → 1.3.22
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/VERSION.yml +1 -1
- data/lib/emissary.rb +1 -1
- data/lib/emissary/config.rb +1 -1
- data/lib/emissary/inifile.rb +124 -122
- metadata +3 -3
data/VERSION.yml
CHANGED
data/lib/emissary.rb
CHANGED
@@ -221,6 +221,6 @@ end # module Emissary
|
|
221
221
|
|
222
222
|
$:.unshift Emissary::LIBPATH.to_s
|
223
223
|
|
224
|
-
[ :errors, :logger, :operator, :agent, :identity, :message, :config, :gem_helper ].each do |sublib|
|
224
|
+
[ :inifile, :errors, :logger, :operator, :agent, :identity, :message, :config, :gem_helper ].each do |sublib|
|
225
225
|
require Emissary.sublib_path sublib.to_s
|
226
226
|
end
|
data/lib/emissary/config.rb
CHANGED
data/lib/emissary/inifile.rb
CHANGED
@@ -2,146 +2,148 @@
|
|
2
2
|
# This class represents the INI file and can be used to parse INI files.
|
3
3
|
# Derived from IniFile gem, found on http://rubyforge.org/projects/inifile/
|
4
4
|
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
5
|
+
module Emissary
|
6
|
+
class IniFile
|
7
|
+
|
8
|
+
#
|
9
|
+
# call-seq:
|
10
|
+
# IniFile.load( filename )
|
11
|
+
# IniFile.load( filename, options )
|
12
|
+
#
|
13
|
+
# Open the given _filename_ and load the contents of the INI file.
|
14
|
+
# The following _options_ can be passed to this method:
|
15
|
+
#
|
16
|
+
# :comment => ';' The line comment character(s)
|
17
|
+
# :parameter => '=' The parameter / value separator
|
18
|
+
#
|
19
|
+
def self.load( filename, opts = {} )
|
20
|
+
if filename
|
21
|
+
new(filename, opts)
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
23
25
|
end
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def initialize( filename, opts = {} )
|
28
|
+
@fn = filename
|
29
|
+
@comment = opts[:comment] || '#'
|
30
|
+
@param = opts[:parameter] || '='
|
31
|
+
@ini = Hash.new {|h,k| h[k] = Hash.new}
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
@rgxp_comment = /^\s*$|^\s*[#{@comment}]/
|
34
|
+
@rgxp_section = /^\s*\[([^\]]+)\]/
|
35
|
+
@rgxp_param = /^([^#{@param}]+)#{@param}(.*)$/
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
parse
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
40
|
+
#
|
41
|
+
# call-seq:
|
42
|
+
# each {|section, parameter, value| block}
|
43
|
+
#
|
44
|
+
# Yield each _section_, _parameter_, _value_ in turn to the given
|
45
|
+
# _block_. The method returns immediately if no block is supplied.
|
46
|
+
#
|
47
|
+
def each
|
48
|
+
return unless block_given?
|
49
|
+
@ini.each do |section,hash|
|
50
|
+
hash.each do |param,val|
|
51
|
+
yield section, param, val
|
52
|
+
end
|
51
53
|
end
|
54
|
+
self
|
52
55
|
end
|
53
|
-
self
|
54
|
-
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
57
|
+
#
|
58
|
+
# call-seq:
|
59
|
+
# each_section {|section| block}
|
60
|
+
#
|
61
|
+
# Yield each _section_ in turn to the given _block_. The method returns
|
62
|
+
# immediately if no block is supplied.
|
63
|
+
#
|
64
|
+
def each_section
|
65
|
+
return unless block_given?
|
66
|
+
@ini.each_key {|section| yield section}
|
67
|
+
self
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
70
|
+
#
|
71
|
+
# call-seq:
|
72
|
+
# ini_file[section]
|
73
|
+
#
|
74
|
+
# Get the hash of parameter/value pairs for the given _section_.
|
75
|
+
#
|
76
|
+
def []( section )
|
77
|
+
return nil if section.nil?
|
78
|
+
@ini[section.to_s]
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
81
|
+
#
|
82
|
+
# call-seq:
|
83
|
+
# has_section?( section )
|
84
|
+
#
|
85
|
+
# Returns +true+ if the named _section_ exists in the INI file.
|
86
|
+
#
|
87
|
+
def has_section?( section )
|
88
|
+
@ini.has_key? section.to_s
|
89
|
+
end
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
91
|
+
#
|
92
|
+
# call-seq:
|
93
|
+
# sections
|
94
|
+
#
|
95
|
+
# Returns an array of the section names.
|
96
|
+
#
|
97
|
+
def sections
|
98
|
+
@ini.keys
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
+
private
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
103
|
+
def cleanup(str)
|
104
|
+
str = str.strip
|
105
|
+
first = str[0..0]; last = str[-1..-1]
|
106
|
+
str = str[1..-2] if first == last && (first == '"' || first == "'")
|
107
|
+
end
|
108
|
+
#
|
109
|
+
# call-seq
|
110
|
+
# parse
|
111
|
+
#
|
112
|
+
# Parse the ini file contents.
|
113
|
+
#
|
114
|
+
def parse
|
115
|
+
return unless ::Kernel.test ?f, @fn
|
116
|
+
section = nil
|
117
|
+
|
118
|
+
::File.open(@fn, 'r') do |f|
|
119
|
+
while line = f.gets
|
120
|
+
line = line.chomp
|
121
|
+
|
122
|
+
case line
|
123
|
+
# ignore blank lines and comment lines
|
124
|
+
when @rgxp_comment: next
|
125
|
+
|
126
|
+
# this is a section declaration
|
127
|
+
when @rgxp_section: section = @ini[$1.strip.downcase]
|
128
|
+
|
129
|
+
# otherwise we have a parameter
|
130
|
+
when @rgxp_param
|
131
|
+
begin
|
132
|
+
val = $2.strip
|
133
|
+
val = val[1..-2] if val[0..0] == "'" || val[-1..-1] == '"'
|
134
|
+
section[$1.strip.downcase.to_sym] = val
|
135
|
+
rescue NoMethodError
|
136
|
+
raise "Bad configuration - inifile parameter encountered before first section"
|
137
|
+
end
|
138
|
+
|
139
|
+
else
|
140
|
+
raise "Bad configuration -- inifile could not parse line '#{line}"
|
136
141
|
end
|
137
|
-
|
138
|
-
else
|
139
|
-
raise "Bad configuration -- inifile could not parse line '#{line}"
|
140
142
|
end
|
141
143
|
end
|
142
144
|
end
|
143
|
-
end
|
144
145
|
|
146
|
+
end
|
145
147
|
end
|
146
148
|
|
147
149
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emissary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 22
|
10
|
+
version: 1.3.22
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Carl P. Corliss
|