Module: WorldDb
- Defined in:
- lib/worlddb/models/forward.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/usage.rb,
lib/worlddb/readers/city.rb,
lib/worlddb/readers/lang.rb,
lib/worlddb/models/region.rb,
lib/worlddb/readers/usage.rb,
lib/worlddb/models/country.rb,
lib/worlddb/readers/region.rb,
lib/worlddb/readers/country.rb,
lib/worlddb/models/continent.rb,
lib/worlddb/models/city_compat.rb,
lib/worlddb/models/lang_compat.rb,
lib/worlddb/models/country_code.rb,
lib/worlddb/models/region_compat.rb,
lib/worlddb/models/country_compat.rb,
lib/worlddb/models/continent_compat.rb
Overview
forward references
require first to resolve circular references
Defined Under Namespace
Modules: Matcher, Model Classes: CityReader, CountryReader, CreateDb, Deleter, LangReader, Reader, ReaderBase, RegionReader, 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??
2- PATCH =
2- 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 Nguyenruby.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}/"- REGION_KEY_PATTERN =
'\A[a-z]+\z'- REGION_KEY_PATTERN_MESSAGE =
"expected one or more lowercase letters a-z /#{REGION_KEY_PATTERN}/"- REGION_CODE_PATTERN =
'\A[A-Z_]{2,3}\z'- REGION_CODE_PATTERN_MESSAGE =
"expected two or three uppercase letters A-Z (and _) /#{REGION_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
136 137 138 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 |
# File 'lib/worlddb/models.rb', line 136 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
80 81 82 83 |
# File 'lib/worlddb/models.rb', line 80 def self.create CreateDb.new.up ConfDb::Model::Prop.create!( key: 'db.schema.world.version', value: VERSION ) end |
.create_all ⇒ Object
85 86 87 88 89 90 |
# File 'lib/worlddb/models.rb', line 85 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!)
118 119 120 121 |
# File 'lib/worlddb/models.rb', line 118 def self.delete! puts '*** deleting world table records/data...' Deleter.new.run end |
.delete_all!(opts = {}) ⇒ Object
method delete!
123 124 125 126 127 128 |
# File 'lib/worlddb/models.rb', line 123 def self.delete_all!( opts={} ) LogDb.delete! ConfDb.delete! TagDb.delete! WorldDb.delete! end |
.read(ary, include_path) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/worlddb/models.rb', line 93 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
112 113 114 |
# File 'lib/worlddb/models.rb', line 112 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
101 102 103 104 |
# File 'lib/worlddb/models.rb', line 101 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 ??
106 107 108 109 110 |
# File 'lib/worlddb/models.rb', line 106 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.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}" end |
.setup_in_memory_db ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/worlddb/models.rb', line 178 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
131 132 133 |
# File 'lib/worlddb/models.rb', line 131 def self.tables Stats.new.tables end |
.version ⇒ Object
11 12 13 |
# File 'lib/worlddb/version.rb', line 11 def self.version VERSION end |