Class: OpenSSL::Config
- Inherits:
-
Object
- Object
- OpenSSL::Config
- Includes:
- Enumerable
- Defined in:
- lib/openssl/config.rb,
ossl_config.c
Constant Summary
- DEFAULT_CONFIG_FILE =
rb_str_new2(default_config_file)
Class Method Summary (collapse)
-
+ (Object) get_key_string(data, section, key)
:nodoc:.
- + (Object) parse(str)
- + (Object) parse_config(io)
Instance Method Summary (collapse)
- - (Object) [](section)
- - (Object) []=(section, pairs)
- - (Object) add_value(section, key, value)
- - (Object) each
- - (Object) get_value(section, key)
-
- (Config) initialize(filename = nil)
constructor
A new instance of Config.
- - (Object) inspect
- - (Object) section(name)
- - (Object) sections
- - (Object) to_s
- - (Object) value(arg1, arg2 = nil)
Constructor Details
- (Config) initialize(filename = nil)
A new instance of Config
212 213 214 215 216 217 218 219 220 221 |
# File 'lib/openssl/config.rb', line 212 def initialize(filename = nil) @data = {} if filename File.open(filename.to_s) do |file| Config.parse_config(file).each do |section, hash| self[section] = hash end end end end |
Class Method Details
+ (Object) get_key_string(data, section, key)
:nodoc:
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/openssl/config.rb', line 39 def get_key_string(data, section, key) # :nodoc: if v = data[section] && data[section][key] return v elsif section == 'ENV' if v = ENV[key] return v end end if v = data['default'] && data['default'][key] return v end end |
+ (Object) parse(str)
20 21 22 23 24 25 26 |
# File 'lib/openssl/config.rb', line 20 def parse(str) c = new() parse_config(StringIO.new(str)).each do |section, hash| c[section] = hash end c end |
+ (Object) parse_config(io)
30 31 32 33 34 35 36 37 |
# File 'lib/openssl/config.rb', line 30 def parse_config(io) begin parse_config_lines(io) rescue ConfigError => e e..replace("error in line #{io.lineno}: " + e.) raise end end |
Instance Method Details
- (Object) [](section)
248 249 250 |
# File 'lib/openssl/config.rb', line 248 def [](section) @data[section] || {} end |
- (Object) []=(section, pairs)
257 258 259 260 261 262 263 |
# File 'lib/openssl/config.rb', line 257 def []=(section, pairs) check_modify @data[section] ||= {} pairs.each do |key, value| self.add_value(section, key, value) end end |
- (Object) add_value(section, key, value)
243 244 245 246 |
# File 'lib/openssl/config.rb', line 243 def add_value(section, key, value) check_modify (@data[section] ||= {})[key] = value end |
- (Object) each
281 282 283 284 285 286 287 |
# File 'lib/openssl/config.rb', line 281 def each @data.each do |section, hash| hash.each do |key, value| yield [section, key, value] end end end |
- (Object) get_value(section, key)
223 224 225 226 227 228 229 |
# File 'lib/openssl/config.rb', line 223 def get_value(section, key) if section.nil? raise TypeError.new('nil not allowed') end section = 'default' if section.empty? get_key_string(section, key) end |
- (Object) inspect
289 290 291 |
# File 'lib/openssl/config.rb', line 289 def inspect "#<#{self.class.name} sections=#{sections.inspect}>" end |
- (Object) section(name)
252 253 254 255 |
# File 'lib/openssl/config.rb', line 252 def section(name) warn('Config#section is deprecated; use Config#[]') @data[name] || {} end |
- (Object) sections
265 266 267 |
# File 'lib/openssl/config.rb', line 265 def sections @data.keys end |
- (Object) to_s
269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/openssl/config.rb', line 269 def to_s ary = [] @data.keys.sort.each do |section| ary << "[ #{section} ]\n" @data[section].keys.each do |key| ary << "#{key}=#{@data[section][key]}\n" end ary << "\n" end ary.join end |
- (Object) value(arg1, arg2 = nil)
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/openssl/config.rb', line 231 def value(arg1, arg2 = nil) warn('Config#value is deprecated; use Config#get_value') if arg2.nil? section, key = 'default', arg1 else section, key = arg1, arg2 end section ||= 'default' section = 'default' if section.empty? get_key_string(section, key) end |