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.



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

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.



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

def arch
  @arch
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

Class Method Details

.aboutObject



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

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

.versionObject



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

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

Instance Method Details

#runObject



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

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