Module: WorldDb
- Defined in:
- lib/worlddb/matcher_adm.rb,
lib/worlddb/stats.rb,
lib/worlddb/models.rb,
lib/worlddb/reader.rb,
lib/worlddb/schema.rb,
lib/worlddb/deleter.rb,
lib/worlddb/matcher.rb,
lib/worlddb/version.rb,
lib/worlddb/patterns.rb,
lib/worlddb/reader_zip.rb,
lib/worlddb/models/city.rb,
lib/worlddb/models/lang.rb,
lib/worlddb/models/name.rb,
lib/worlddb/reader_file.rb,
lib/worlddb/models/place.rb,
lib/worlddb/models/state.rb,
lib/worlddb/models/usage.rb,
lib/worlddb/readers/base.rb,
lib/worlddb/readers/city.rb,
lib/worlddb/readers/lang.rb,
lib/worlddb/readers/state.rb,
lib/worlddb/readers/usage.rb,
lib/worlddb/models/country.rb,
lib/worlddb/models/forward.rb,
lib/worlddb/readers/country.rb,
lib/worlddb/models/city_base.rb,
lib/worlddb/models/continent.rb,
lib/worlddb/models/state_base.rb,
lib/worlddb/readers/state_tree.rb,
lib/worlddb/models/country_code.rb,
lib/worlddb/reports/country_report.rb
Overview
forward references
require first to resolve circular references
Defined Under Namespace
Modules: Matcher, Model Classes: CityReader, CountryReader, CountryReport, CountyReader, CreateDb, Deleter, LangReader, MuniReader, PartReader, Reader, ReaderBase, ReaderBaseWithMoreAttribs, ReaderBaseWithOpts, StateReader, StateTreeReader, Stats, UsageReader, ZipReader
Constant Summary collapse
- MAJOR =
sync version w/ sport.db n friends - why? why not?
2
- MINOR =
todo: namespace inside version or something - why? why not??
4
- PATCH =
1
- VERSION =
[MAJOR,MINOR,PATCH].join('.')
- 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!!
'\A[a-z]{2,}\z'
- COUNTRY_KEY_PATTERN_MESSAGE =
allow two AND three letter keys e.g. at, mx, eng, sco, etc.
"expected two or more lowercase letters a-z /#{COUNTRY_KEY_PATTERN}/"
- COUNTRY_CODE_PATTERN =
'\A[A-Z]{3,}\z'
- COUNTRY_CODE_PATTERN_MESSAGE =
"expected three or more uppercase letters A-Z /#{COUNTRY_CODE_PATTERN}/"
- STATE_KEY_PATTERN =
'\A[a-z]+\z'
- STATE_KEY_PATTERN_MESSAGE =
"expected one or more lowercase letters a-z /#{STATE_KEY_PATTERN}/"
- STATE_CODE_PATTERN =
'\A[A-Z_]{2,3}\z'
- STATE_CODE_PATTERN_MESSAGE =
"expected two or three uppercase letters A-Z (and _) /#{STATE_CODE_PATTERN}/"
- CITY_KEY_PATTERN =
'\A[a-z]{3,}\z'
- CITY_KEY_PATTERN_MESSAGE =
"expected three or more lowercase letters a-z' /#{CITY_KEY_PATTERN}/"
- CITY_CODE_PATTERN =
'\A[A-Z_]{3}\z'
- CITY_CODE_PATTERN_MESSAGE =
"expected three uppercase letters A-Z (and _)' /#{CITY_CODE_PATTERN}/"
- LANG_KEY_PATTERN =
'\A[a-z]{2}\z'
- LANG_KEY_PATTERN_MESSAGE =
"expected two lowercase letters a-z' /#{LANG_KEY_PATTERN}/"
- Models =
note: convenience alias for Model lets you use include WorldDb::Models
Model
Class Method Summary collapse
- .banner ⇒ Object
- .connect(config = {}) ⇒ Object
- .create ⇒ Object
- .create_all ⇒ Object
-
.delete! ⇒ Object
delete ALL records (use with care!).
-
.delete_all!(opts = {}) ⇒ Object
method delete!.
- .read(ary, include_path) ⇒ Object
-
.read_all(include_path, opts = {}) ⇒ Object
load all builtins (using plain text reader); helper for convenience.
- .read_setup(setup, include_path, opts = {}) ⇒ Object
-
.read_setup_from_zip(zip_name, setup, include_path, opts = {}) ⇒ Object
todo/check - use a better (shorter) name ??.
- .root ⇒ Object
- .setup_in_memory_db ⇒ Object
- .tables ⇒ Object
- .version ⇒ Object
Class Method Details
.banner ⇒ Object
15 16 17 |
# File 'lib/worlddb/version.rb', line 15 def self. "worlddb-models/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]" end |
.connect(config = {}) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# 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 ⇒ Object
87 88 89 90 |
# 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 ⇒ Object
92 93 94 95 96 97 |
# 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! ⇒ Object
delete ALL records (use with care!)
125 126 127 128 |
# File 'lib/worlddb/models.rb', line 125 def self.delete! puts '*** deleting world table records/data...' Deleter.new.run end |
.delete_all!(opts = {}) ⇒ Object
method delete!
130 131 132 133 134 135 |
# 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) ⇒ Object
100 101 102 103 104 105 |
# 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 = {}) ⇒ Object
load all builtins (using plain text reader); helper for convenience
119 120 121 |
# 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 = {}) ⇒ Object
108 109 110 111 |
# 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 = {}) ⇒ Object
todo/check - use a better (shorter) name ??
113 114 115 116 117 |
# 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 ⇒ Object
19 20 21 |
# File 'lib/worlddb/version.rb', line 19 def self.root "#{File.( File.dirname(File.dirname(File.dirname(__FILE__))) )}" end |
.setup_in_memory_db ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 |
# 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 ⇒ Object
138 139 140 |
# File 'lib/worlddb/models.rb', line 138 def self.tables Stats.new.tables end |
.version ⇒ Object
11 12 13 |
# File 'lib/worlddb/version.rb', line 11 def self.version VERSION end |