module WorldDb
matchers for adm2,adm3,etc
e.g. parts (regierungsbezirke) counties (kreise,bezirke)
forward references
require first to resolve circular references
Constants
- CITY_CODE_PATTERN
- CITY_CODE_PATTERN_MESSAGE
- CITY_KEY_PATTERN
- CITY_KEY_PATTERN_MESSAGE
- COUNTRY_CODE_PATTERN
- COUNTRY_CODE_PATTERN_MESSAGE
- COUNTRY_KEY_PATTERN
todo/fix: change to COUNTRY_KEY_RE and make it regexp type!! todo/fix: change to COUNTRY_CODE_RE and make it regexp type!!
- COUNTRY_KEY_PATTERN_MESSAGE
- LANG_KEY_PATTERN
- LANG_KEY_PATTERN_MESSAGE
- MAJOR
sync version w/ sport.db n friends - why? why not?
- MINOR
- Models
note: convenience alias for
Model
lets you use includeWorldDb::Models
- PATCH
- STATE_CODE_PATTERN
- STATE_CODE_PATTERN_MESSAGE
- STATE_KEY_PATTERN
- STATE_KEY_PATTERN_MESSAGE
- VERSION
Public Class Methods
connect( config={} )
click to toggle source
# File lib/worlddb/models.rb, line 143 def self.connect( config={} ) if config.empty? puts "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<" ### change default to ./sport.db ?? why? why not? db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///world.db' ) if db.scheme == 'postgres' config = { adapter: 'postgresql', host: db.host, port: db.port, username: db.user, password: db.password, database: db.path[1..-1], encoding: 'utf8' } else # assume sqlite3 config = { adapter: db.scheme, # sqlite3 database: db.path[1..-1] # world.db (NB: cut off leading /, thus 1..-1) } end end ## todo/check: use if defined?( JRUBY_VERSION ) instead ?? if RUBY_PLATFORM =~ /java/ && config[:adapter] == 'sqlite3' # quick hack for JRuby sqlite3 support via jdbc puts "jruby quick hack - adding jdbc libs for jruby sqlite3 database support" require 'jdbc/sqlite3' require 'active_record/connection_adapters/jdbc_adapter' require 'active_record/connection_adapters/jdbcsqlite3_adapter' end puts "Connecting to db using settings: " pp config ActiveRecord::Base.establish_connection( config ) # ActiveRecord::Base.logger = Logger.new( STDOUT ) end
create()
click to toggle source
# File lib/worlddb/models.rb, line 87 def self.create CreateDb.new.up ConfDb::Model::Prop.create!( key: 'db.schema.world.version', value: VERSION ) end
create_all()
click to toggle source
# File lib/worlddb/models.rb, line 92 def self.create_all LogDb.create # add logs table ConfDb.create # add props table TagDb.create # add tags, taggings table WorldDb.create end
delete!()
click to toggle source
delete ALL records (use with care!)
# File lib/worlddb/models.rb, line 125 def self.delete! puts '*** deleting world table records/data...' Deleter.new.run end
delete_all!( opts={} )
click to toggle source
# File lib/worlddb/models.rb, line 130 def self.delete_all!( opts={} ) LogDb.delete! ConfDb.delete! TagDb.delete! WorldDb.delete! end
read( ary, include_path )
click to toggle source
# File lib/worlddb/models.rb, line 100 def self.read( ary, include_path ) reader = Reader.new( include_path ) ary.each do |name| reader.load( name ) end end
read_all( include_path, opts={} )
click to toggle source
# File lib/worlddb/models.rb, line 119 def self.read_all( include_path, opts={} ) # load all builtins (using plain text reader); helper for convenience read_setup( 'setups/all', include_path, opts ) end
read_setup( setup, include_path, opts={} )
click to toggle source
# File lib/worlddb/models.rb, line 108 def self.read_setup( setup, include_path, opts={} ) reader = Reader.new( include_path, opts ) reader.load_setup( setup ) end
read_setup_from_zip( zip_name, setup, include_path, opts={} )
click to toggle source
# File lib/worlddb/models.rb, line 113 def self.read_setup_from_zip( zip_name, setup, include_path, opts={} ) ## todo/check - use a better (shorter) name ?? reader = ZipReader.new( zip_name, include_path, opts ) reader.load_setup( setup ) reader.close end
root()
click to toggle source
# File lib/worlddb/version.rb, line 19 def self.root "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}" end
setup_in_memory_db()
click to toggle source
# File lib/worlddb/models.rb, line 185 def self.setup_in_memory_db # Database Setup & Config ActiveRecord::Base.logger = Logger.new( STDOUT ) ## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting? self.connect( adapter: 'sqlite3', database: ':memory:' ) ## build schema WorldDb.create_all end
tables()
click to toggle source
# File lib/worlddb/models.rb, line 138 def self.tables Stats.new.tables end
version()
click to toggle source
# File lib/worlddb/version.rb, line 11 def self.version VERSION end