Module: Pwnbus::Configdb
- Defined in:
- lib/pwnbus/configdb.rb,
lib/pwnbus/configdb/db.rb,
lib/pwnbus/configdb/files.rb
Overview
:nodoc: file-related functionality
Defined Under Namespace
Class Method Summary collapse
-
.open(name, options = {}) ⇒ Object
Opens a configuration database.
Class Method Details
.open(name, options = {}) ⇒ Object
Opens a configuration database. The database is created if it doesn’t exist.
Args:
name:: the database name; if the name starts with a ., the database is
only readable to the current user, otherwise it is public (readable
to everyone, but only writable by the current user)
options:: the following keys are recognized
:read:: opens the database only for reading
Yields a proxy object that can be used to access the database.
Returns the value produced by the block.
Example:
Pwnbus::Configdb.open('system') do |system|
system.os.name = 'Ubuntu'
system.os.version = '10.04.1'
end
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pwnbus/configdb.rb', line 27 def self.open(name, = {}) db_path = Files.find_db(name) || Files.create_db(name, ) db_file = Files.open_db(db_path, ) db = Db.new db_file begin return_value = yield db.proxy if db.dirty? Files.write_db db_path, do |wf| db.write wf end end return_value ensure db.close db_file.close end end |