Class: Rack::Dedos::Executables::Geoipget

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/dedos/executables/geoipget.rb

Defined Under Namespace

Classes: Maxmind

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Geoipget

Returns a new instance of Geoipget.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rack/dedos/executables/geoipget.rb', line 15

def initialize(**options)
  @arch, @dir = 'linux_amd64', '.'
  OptionParser.new do |o|
    o.banner = <<~END
      Download the geoip database from Maxmind.
      Usage: #{::File.basename($0)} CONFIG_FILE
    END
    o.on('-a', '--arch ARCH', String, "architecture (default: #{arch})") { @arch = _1 }
    o.on('-d', '--dir DIR', String, "destination directory (default: #{dir})") { @dir = _1 }
    o.on('-A', '--about', 'show author/license information and exit') { self.class.about }
    o.on('-V', '--version', 'show version and exit') { self.class.version }
  end.parse!
  @config = ARGV.first
end

Instance Attribute Details

#archObject (readonly)

Returns the value of attribute arch.



13
14
15
# File 'lib/rack/dedos/executables/geoipget.rb', line 13

def arch
  @arch
end

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/rack/dedos/executables/geoipget.rb', line 13

def config
  @config
end

#dirObject (readonly)

Returns the value of attribute dir.



13
14
15
# File 'lib/rack/dedos/executables/geoipget.rb', line 13

def dir
  @dir
end

Class Method Details

.aboutObject



35
36
37
38
# File 'lib/rack/dedos/executables/geoipget.rb', line 35

def self.about
  puts 'Written by Sven Schwyn (bitcetera.com) and distributed under MIT license.'
  exit
end

.versionObject



40
41
42
43
# File 'lib/rack/dedos/executables/geoipget.rb', line 40

def self.version
  puts Rack::Dedos::VERSION
  exit
end

Instance Method Details

#runObject



30
31
32
33
# File 'lib/rack/dedos/executables/geoipget.rb', line 30

def run
  fail "cannot read config file #{config}" unless config && ::File.readable?(config)
  Maxmind.new(::File.realpath(config), ::File.realpath(dir), arch).get
end