Class: DBGet::Runner

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



19
20
21
# File 'lib/dbget/runner.rb', line 19

def initialize(options)
  @options = options
end

Class Method Details

.boot(user, options) ⇒ Object



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

def self.boot(user, options)
  self.new(parse_options(user, options)).run!
end

.parse_options(user, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dbget/runner.rb', line 7

def self.parse_options(user, options)
  opts = {}
  opts['user'] = user

  options.each do |o|
    k, v = o.split('=')
    opts[k] = v
  end

  opts
end

Instance Method Details

#dumpObject



51
52
53
# File 'lib/dbget/runner.rb', line 51

def dump
  Controller.boot(@options)
end

#format_date(date) ⇒ Object



45
46
47
48
49
# File 'lib/dbget/runner.rb', line 45

def format_date(date)
  unless date == 'xxxx-xx-xx'
    Date.strptime(date, "%Y-%m-%d")
  end
end

#get_dbget_pathObject



55
56
57
58
59
60
61
# File 'lib/dbget/runner.rb', line 55

def get_dbget_path
  if ENV.include?('DBGET_PATH')
    ENV['DBGET_PATH']
  else
    raise "DBGET_PATH not defined"
  end
end

#get_final_collection(collection) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/dbget/runner.rb', line 37

def get_final_collection(collection)
  unless collection == 'EMPTY'
    collection.split(',')
  else
    []
  end
end

#init_config(dbget_path) ⇒ Object



63
64
65
# File 'lib/dbget/runner.rb', line 63

def init_config(dbget_path)
  DBGet.read_config(dbget_path)
end

#prepare_dump_optionsObject



29
30
31
32
33
34
35
# File 'lib/dbget/runner.rb', line 29

def prepare_dump_options
  @options['collections'] = get_final_collection(@options['collections'])
  @options['date'] = format_date(@options['date'])
  @options['clean'] = Utils.to_bool(@options['clean'])
  @options['verbose'] = Utils.to_bool(@options['verbose'])
  @options['append_date'] = Utils.to_bool(@options['append_date'])
end

#run!Object



23
24
25
26
27
# File 'lib/dbget/runner.rb', line 23

def run!
  init_config(get_dbget_path)
  prepare_dump_options
  dump
end