Initial commit

This commit is contained in:
Yaser
2026-08-13 19:56:46 +03:30
commit de1d57a67b
474 changed files with 43185 additions and 0 deletions

29
lib/barong/geo_ip.rb Normal file
View File

@@ -0,0 +1,29 @@
# frozen_string_literal: true
module Barong
# MaxmindDB reader adapter
module GeoIP
class << self
attr_accessor :lang
# Usage: city = Barong::GeoIP.get(ip: ip, key: :city)
def info(ip:, key:)
record = reader.get(ip)
return unless record
case key.to_sym
when :country
return record['country']['names'][lang] if record['country']
when :continent
return record['continent']['names'][lang] if record['continent']
end
end
private
def reader
@reader ||= MaxMind::DB.new(Barong::App.config.maxminddb_path, mode: MaxMind::DB::MODE_MEMORY)
end
end
end
end