Module: Ronin::Database
Constants
- CONFIG_FILE
- File.join(Config::PATH,'database.yml')
- DEFAULT_CONFIG
- "sqlite3://" + File.join(Config::PATH,'database.sqlite3')
- DEFAULT_LOG_LEVEL
- :info
- DEFAULT_LOG_PATH
- File.join(Config::PATH,'database.log')
Public Visibility
Public Class Method Summary
| config |
Returns the Database configuration that is stored in the. |
|---|---|
| config=(configuration) |
Sets the Database configuration. |
| log |
Returns: DataMapper::Logger |
| setup(configuration = Database.config, &block) |
Sets up the Database. |
| setup? |
Returns: Boolean |
| setup_log(options = {}) |
Setup the Database log. Returns: DataMapper::Logger |
| update!(&block) |
Updates the Database, by running auto-upgrades, but only if the. |
Public Class Method Details
config
Returns the Database configuration that is stored in the CONFIG_FILE. Defaults to DEFAULT_CONFIG if CONFIG_FILE does not exist.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ronin/database/database.rb', line 55 def Database.config unless (class_variable_defined?('@@ronin_database_config')) @@ronin_database_config = DEFAULT_CONFIG if File.file?(CONFIG_FILE) conf = YAML.load(CONFIG_FILE) unless (conf.kind_of?(Hash) || conf.kind_of?(String)) raise(InvalidConfig,"#{CONFIG_FILE} must contain either a Hash or a String",caller) end @@ronin_database_config = conf end end return @@ronin_database_config ||= DEFAULT_CONFIG end |
config=
Sets the Database configuration.
79 80 81 |
# File 'lib/ronin/database/database.rb', line 79 def Database.config=(configuration) @@ronin_database_config = configuration end |
log
87 88 89 |
# File 'lib/ronin/database/database.rb', line 87 def Database.log @@ronin_database_log ||= nil end |
setup
Sets up the Database.
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ronin/database/database.rb', line 152 def Database.setup(configuration=Database.config,&block) # setup the database log Database.setup_log unless Database.log # setup the database repository DataMapper.setup(Model::REPOSITORY_NAME, configuration) Database.update!(&block) return nil end |
setup?
122 123 124 125 126 |
# File 'lib/ronin/database/database.rb', line 122 def Database.setup? repository = DataMapper.repository(Model::REPOSITORY_NAME) return repository.class.adapters.has_key?(repository.name) end |
setup_log
Setup the Database log.
110 111 112 113 114 115 116 |
# File 'lib/ronin/database/database.rb', line 110 def Database.setup_log(={}) path = ([:path] || DEFAULT_LOG_PATH) stream = ([:stream] || File.new(path,'w+')) level = ([:level] || DEFAULT_LOG_LEVEL) return @@ronin_database_log = DataMapper::Logger.new(stream,level) end |
update!
Updates the Database, by running auto-upgrades, but only if the Database is already setup.
135 136 137 138 139 140 |
# File 'lib/ronin/database/database.rb', line 135 def Database.update!(&block) block.call if block DataMapper.auto_upgrade!(Model::REPOSITORY_NAME) if Database.setup? return nil end |