Class: WR::Inifile
- Inherits:
-
Hash
- Object
- Hash
- WR::Inifile
- Defined in:
- lib/wrb/components/inifile.rb
Overview
Handles a Inifile (*.ini) like a Hash. (WRB orignal)
Inifile formats are following.<pre>
[section]
key=value
...</pre>
Class Method Summary collapse
-
.open(path, &block) ⇒ Object
Opens a file specified path.
If block is given, opens for writing and closes automaticaly.
Instance Method Summary collapse
-
#close ⇒ Object
(also: #flash)
Closes and writes out to the file.
-
#open(path) ⇒ Object
Opens a file specified path.
If block is given, opens for writing and closes automaticaly. -
#path ⇒ Object
Gets an absolute path to this inifile.
Class Method Details
.open(path, &block) ⇒ Object
Opens a file specified path.
If block is given, opens for writing and closes automaticaly.
18 19 20 |
# File 'lib/wrb/components/inifile.rb', line 18 def self.open(path, &block) self.new().open(path, &block) end |
Instance Method Details
#close ⇒ Object Also known as: flash
Closes and writes out to the file.
71 72 73 |
# File 'lib/wrb/components/inifile.rb', line 71 def close() File.open(@_path, 'w'){|f| f.write(_format) } end |
#open(path) ⇒ Object
Opens a file specified path.
If block is given, opens for writing and closes automaticaly.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/wrb/components/inifile.rb', line 54 def open(path) @_path = File.(path) if block_given? Mutex.new.synchronize { File.open(@_path, 'w+'){|f| _parse(f.read) yield self f.write(_format) } } else File.open(@_path, 'r'){|f| _parse(f.read)} end self end |
#path ⇒ Object
Gets an absolute path to this inifile.
77 78 79 |
# File 'lib/wrb/components/inifile.rb', line 77 def path() @_path end |