Class: DBGet::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/dbget/runner.rb

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



3
4
5
6
7
8
# File 'lib/dbget/runner.rb', line 3

def initialize
  @options = {}
  set_default_options
  @optparse = init_option_parser
  @args = nil
end

Instance Method Details

#check_pathObject



93
94
95
96
97
98
99
# File 'lib/dbget/runner.rb', line 93

def check_path
  if ENV.include?('DBGET_PATH')
    @options[:dbget_path] = ENV['DBGET_PATH']
  else
    raise "Cannot find DBGET_PATH!"
  end
end

#controllerObject



80
81
82
83
84
# File 'lib/dbget/runner.rb', line 80

def controller
  controller = DBGet::Controller.new(@args, @options)
  controller.boot
  controller.send_data!
end

#has_arguments?Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
# File 'lib/dbget/runner.rb', line 86

def has_arguments?
  if @args.length == 0
    puts @optparse.help
    exit
  end
end

#init_option_parserObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dbget/runner.rb', line 10

def init_option_parser
  optparse = OptionParser.new do |opts|
    opts.banner = "Usage: dbget [options] db1 db2 ...\n"
    opts.separator "Options:"

    opts.on('-d', '--date DATE', 'Date of database dump (yyyy-mm-dd).') do |date|
      @options[:date] = date
    end

    opts.on('-c', '--clean', 'Drops the database before dumping') do
      @options[:clean] = true
    end

    opts.on('-k', '--key KEY', 'Specify ssh connection key') do |key|
      @options[:key] = key
    end

    opts.on('-s', '--server SERVER', 'Specify the server that contained the database.') do |server|
      @options[:server] = server
    end

    opts.on('-a', '--append-date', 'Append the given date as suffix') do
      @options[:append_date] = true
    end

    opts.on('--collections COLLECTION', 'Only dump specific mongodb collections separated by comma') do |collection|
      @options[:collections] = collection
    end

    opts.on('--n', '--name NAME', 'Specify a custom name/key for databases') do |name|
      @options[:name] = name
    end

    opts.on('-v', '--verbose', 'Execute NERD mode!') do
      @options[:verbose] = true
    end

    opts.on('-V', '--version', 'Version') do
      puts DBGet::VERSION
      exit
    end

    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit
    end
  end

  optparse
end

#run!(args, type) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/dbget/runner.rb', line 69

def run!(args, type)
  check_path
  @args = args
  has_arguments?

  @optparse.parse!
  @options[:db_type] = type

  controller
end

#set_default_optionsObject



61
62
63
64
65
66
67
# File 'lib/dbget/runner.rb', line 61

def set_default_options
  @options[:append_date] = false
  @options[:verbose] = false
  @options[:clean] = false
  @options[:date] = 'xxxx-xx-xx'
  @options[:collections] = 'EMPTY'
end