Module: DbipUtil
- Extended by:
- DbipUtil
- Included in:
- DbipUtil
- Defined in:
- lib/dbip_util.rb,
lib/dbip_util/version.rb,
sig/dbip_util.rbs,
sig/dbip_util/version.rbs
Overview
DbipUtil includes DB-IP Lite databases and a simple interface to them, based on maxmind-db gem.
Constant Summary collapse
- DB_VERSION =
"2026.08"- VERSION =
"0.1.2.#{DB_VERSION}".freeze
- AST =
- City =
- Country =
Instance Method Summary collapse
- #const_missing(const) ⇒ MaxMind::DB
- #db_path(db) ⇒ String
- #ensure_provisioned! ⇒ Object
- #open(db, options = {}) ⇒ MaxMind::DB
Instance Method Details
#const_missing(const) ⇒ MaxMind::DB
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dbip_util.rb', line 18 def const_missing(const) case const when :Country const_set(const, open(:country)) when :City const_set(const, open(:city)) when :ASN const_set(const, open(:asn)) else super end end |
#db_path(db) ⇒ String
33 34 35 |
# File 'lib/dbip_util.rb', line 33 def db_path(db) __dir__ + "/dbip_util/db/dbip-#{db}-lite.mmdb" end |
#ensure_provisioned! ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/dbip_util.rb', line 37 def ensure_provisioned! # Check for a sample database. If not present, provision it from Rubygems. system "#{__dir__}/../bin/dbiputil-provision" unless File.exist?(db_path(:country)) rescue StandardError warn "Couldn't provision a database! Use a `dbip_util` gem from Rubygems, as it includes a database." raise end |
#open(db, options = {}) ⇒ MaxMind::DB
10 11 12 13 14 15 16 |
# File 'lib/dbip_util.rb', line 10 def open(db, = {}) ensure_provisioned! = { mode: MaxMind::DB::MODE_FILE }.merge() fn = db_path(db) MaxMind::DB.new(fn, ) end |