lib/ronin/database/database.rb in ronin-0.2.2 vs lib/ronin/database/database.rb in ronin-0.2.3

- old
+ new

@@ -20,10 +20,11 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #++ # require 'ronin/database/exceptions/invalid_config' +require 'ronin/model' require 'ronin/arch' require 'ronin/os' require 'ronin/author' require 'ronin/license' require 'ronin/product' @@ -102,10 +103,29 @@ return @@ronin_database_log = DataMapper::Logger.new(stream,level) end # + # Returns +true+ if the Database is setup, returns +false+ otherwise. + # + def Database.setup? + repository = DataMapper.repository(Model::REPOSITORY_NAME) + + return repository.class.adapters.has_key?(repository.name) + end + + # + # Call the given _block_ then run auto-upgrades on the Database. + # + def Database.update!(&block) + block.call if block + + DataMapper.auto_upgrade!(Model::REPOSITORY_NAME) if Database.setup? + return nil + end + + # # Sets up the Database with the given _configuration_. If # _configuration is not given, +DEFAULT_CONFIG+ will be used to setup # the Database. # def Database.setup(configuration=Database.config,&block) @@ -113,12 +133,10 @@ Database.setup_log unless Database.log # setup the database repository DataMapper.setup(Model::REPOSITORY_NAME, configuration) - block.call if block - - DataMapper.auto_upgrade!(Model::REPOSITORY_NAME) + Database.update!(&block) return nil end end end