class RknIpLookup::Database
Attributes
data[RW]
updated_at[RW]
Public Class Methods
load(skip_cache: false)
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 9 def load(skip_cache: false) return @db if @db && !skip_cache @db = !skip_cache && RknIpLookup.config.database.cache && load_from_file || new.load @db end
load_from_file(filename = nil)
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 24 def load_from_file(filename = nil) filename ||= RknIpLookup.config.database.cache_file_path return unless File.exist? filename @db = Marshal.load(File.read(filename)) end
method_missing(meth, *args)
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 16 def method_missing(meth, *args) load.public_send(meth) end
reload()
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 20 def reload load(skip_cache: true) end
Public Instance Methods
cidrs()
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 53 def cidrs @cidrs ||= Types::Cidrs.new(entries.select { |x| x =~ %r{\.0/\d+} }) end
dump_to_file(filename = nil)
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 40 def dump_to_file(filename = nil) filename ||= RknIpLookup.config.database.cache_file_path File.open(filename, 'w') do |f| f.write Marshal.dump(self) f.close end data end
entries()
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 61 def entries @entries ||= Set.new(data) end
hosts()
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 57 def hosts @hosts ||= [] end
ips()
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 49 def ips @ips ||= Set.new(entries.select { |x| x.match?(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) }) end
load()
click to toggle source
# File lib/rkn_ip_lookup/database.rb, line 31 def load provider_data = RknIpLookup::Provider::Antizapret.fetch self.data = provider_data.data self.updated_at = Time.now dump_to_file if RknIpLookup.config.database.cache self end