emissary 1.3.21 → 1.3.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 3
4
- :patch: 21
4
+ :patch: 22
@@ -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
@@ -32,7 +32,7 @@ module Emissary
32
32
  end
33
33
  end
34
34
 
35
- class ConfigFile < IniFile
35
+ class ConfigFile < Emissary::IniFile
36
36
 
37
37
  attr_reader :ini
38
38
  def initialize( filename, opts = {} )
@@ -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
- class IniFile
6
-
7
- #
8
- # call-seq:
9
- # IniFile.load( filename )
10
- # IniFile.load( filename, options )
11
- #
12
- # Open the given _filename_ and load the contents of the INI file.
13
- # The following _options_ can be passed to this method:
14
- #
15
- # :comment => ';' The line comment character(s)
16
- # :parameter => '=' The parameter / value separator
17
- #
18
- def self.load( filename, opts = {} )
19
- if filename
20
- new(filename, opts)
21
- else
22
- nil
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
- def initialize( filename, opts = {} )
27
- @fn = filename
28
- @comment = opts[:comment] || '#'
29
- @param = opts[:parameter] || '='
30
- @ini = Hash.new {|h,k| h[k] = Hash.new}
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
- @rgxp_comment = /^\s*$|^\s*[#{@comment}]/
33
- @rgxp_section = /^\s*\[([^\]]+)\]/
34
- @rgxp_param = /^([^#{@param}]+)#{@param}(.*)$/
33
+ @rgxp_comment = /^\s*$|^\s*[#{@comment}]/
34
+ @rgxp_section = /^\s*\[([^\]]+)\]/
35
+ @rgxp_param = /^([^#{@param}]+)#{@param}(.*)$/
35
36
 
36
- parse
37
- end
37
+ parse
38
+ end
38
39
 
39
- #
40
- # call-seq:
41
- # each {|section, parameter, value| block}
42
- #
43
- # Yield each _section_, _parameter_, _value_ in turn to the given
44
- # _block_. The method returns immediately if no block is supplied.
45
- #
46
- def each
47
- return unless block_given?
48
- @ini.each do |section,hash|
49
- hash.each do |param,val|
50
- yield section, param, val
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
- # call-seq:
58
- # each_section {|section| block}
59
- #
60
- # Yield each _section_ in turn to the given _block_. The method returns
61
- # immediately if no block is supplied.
62
- #
63
- def each_section
64
- return unless block_given?
65
- @ini.each_key {|section| yield section}
66
- self
67
- end
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
- # call-seq:
71
- # ini_file[section]
72
- #
73
- # Get the hash of parameter/value pairs for the given _section_.
74
- #
75
- def []( section )
76
- return nil if section.nil?
77
- @ini[section.to_s]
78
- end
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
- # call-seq:
82
- # has_section?( section )
83
- #
84
- # Returns +true+ if the named _section_ exists in the INI file.
85
- #
86
- def has_section?( section )
87
- @ini.has_key? section.to_s
88
- end
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
- # call-seq:
92
- # sections
93
- #
94
- # Returns an array of the section names.
95
- #
96
- def sections
97
- @ini.keys
98
- end
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
- private
101
+ private
101
102
 
102
- def cleanup(str)
103
- str = str.strip
104
- first = str[0..0]; last = str[-1..-1]
105
- str = str[1..-2] if first == last && (first == '"' || first == "'")
106
- end
107
- #
108
- # call-seq
109
- # parse
110
- #
111
- # Parse the ini file contents.
112
- #
113
- def parse
114
- return unless ::Kernel.test ?f, @fn
115
- section = nil
116
-
117
- ::File.open(@fn, 'r') do |f|
118
- while line = f.gets
119
- line = line.chomp
120
-
121
- case line
122
- # ignore blank lines and comment lines
123
- when @rgxp_comment: next
124
-
125
- # this is a section declaration
126
- when @rgxp_section: section = @ini[$1.strip.downcase]
127
-
128
- # otherwise we have a parameter
129
- when @rgxp_param
130
- begin
131
- val = $2.strip
132
- val = val[1..-2] if val[0..0] == "'" || val[-1..-1] == '"'
133
- section[$1.strip.downcase.to_sym] = val
134
- rescue NoMethodError
135
- raise "Bad configuration - inifile parameter encountered before first section"
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: 49
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 21
10
- version: 1.3.21
9
+ - 22
10
+ version: 1.3.22
11
11
  platform: ruby
12
12
  authors:
13
13
  - Carl P. Corliss