Class: ExportMongoS3::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/export_mongo_s3/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Application

Returns a new instance of Application.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/export_mongo_s3/application.rb', line 4

def initialize(argv)
  @parser = OptionParser.new

  @params = parse_options(argv)
  @config = parse_config(@params[:config])

  db_options = @config[:mongo]
  db_options.merge!(collections: @config[:export][:collections])

  @db = Db.new(db_options)

  @storage = Storage.new(@config[:s3])
end

Instance Method Details

#runObject



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
# File 'lib/export_mongo_s3/application.rb', line 21

def run

  case
    when @params[:export_list] # EXPORT_LIST

      show_uploaded_files(@params[:export_list])

    when @params[:export_all] # EXPORT_ALL

      dbs_str = @config[:export][:dbs]

      if dbs_str.nil? || dbs_str.empty?
        raise 'config.yml::export.dbs is empty'
      end

      db_names = dbs_str.split(',').each { |db_name| db_name.strip! }

      export(db_names)

    when @params[:export] # EXPORT

      export([@params[:export]])

    when @params[:cron_update] || @params[:cron_clear] # CRON

      cron_options =
          {
              update: @params[:cron_update],
              clear:  @params[:cron_clear],
              config: @params[:config],
              time:   @config[:export][:cron_time],
          }

      Scheduler.new(cron_options).execute

    else
      puts "\n#{@parser}\n"
      exit(0)
  end

end