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??
3
- PATCH =
3
- VERSION =
[MAJOR,MINOR,PATCH].join('.')
- COUNTRY_KEY_PATTERN =
about ruby regexps
try the rubular - Ruby regular expression editor and tester
-> http://rubular.com code -> ?? by ??
Jeff Avallone’s Regexper - Shows State-Automata Diagrams
try -> http://regexper.com code -> https://github.com/javallone/regexper Regular Expressions | The Bastards Book of Ruby by Dan Nguyen
ruby.bastardsbook.com/chapters/regexes/
move to notes regex|patterns on geraldb.github.io ??
'\A[a-z]{2,3}\z'
- COUNTRY_KEY_PATTERN_MESSAGE =
allow two AND three letter keys e.g. at, mx, eng, sco, etc.
"expected two or three lowercase letters a-z /#{COUNTRY_KEY_PATTERN}/"
- COUNTRY_CODE_PATTERN =
'\A[A-Z_]{3}\z'
- COUNTRY_CODE_PATTERN_MESSAGE =
"expected three uppercase letters A-Z (and _) /#{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
139 140 141 142 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 |
# File 'lib/worlddb/models.rb', line 139 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
83 84 85 86 |
# File 'lib/worlddb/models.rb', line 83 def self.create CreateDb.new.up ConfDb::Model::Prop.create!( key: 'db.schema.world.version', value: VERSION ) end |
.create_all ⇒ Object
88 89 90 91 92 93 |
# File 'lib/worlddb/models.rb', line 88 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!)
121 122 123 124 |
# File 'lib/worlddb/models.rb', line 121 def self.delete! puts '*** deleting world table records/data...' Deleter.new.run end |
.delete_all!(opts = {}) ⇒ Object
method delete!
126 127 128 129 130 131 |
# File 'lib/worlddb/models.rb', line 126 def self.delete_all!( opts={} ) LogDb.delete! ConfDb.delete! TagDb.delete! WorldDb.delete! end |
.read(ary, include_path) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/worlddb/models.rb', line 96 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
115 116 117 |
# File 'lib/worlddb/models.rb', line 115 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
104 105 106 107 |
# File 'lib/worlddb/models.rb', line 104 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 ??
109 110 111 112 113 |
# File 'lib/worlddb/models.rb', line 109 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
181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/worlddb/models.rb', line 181 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
134 135 136 |
# File 'lib/worlddb/models.rb', line 134 def self.tables Stats.new.tables end |
.version ⇒ Object
11 12 13 |
# File 'lib/worlddb/version.rb', line 11 def self.version VERSION end |