Class: Squasher::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/squasher/worker.rb

Constant Summary collapse

OPTIONS =
[:d, :r]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, options = []) ⇒ Worker

Returns a new instance of Worker.



13
14
15
16
# File 'lib/squasher/worker.rb', line 13

def initialize(date, options = [])
  @date = date
  @options = options
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



7
8
9
# File 'lib/squasher/worker.rb', line 7

def date
  @date
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/squasher/worker.rb', line 7

def options
  @options
end

Class Method Details

.process(*args) ⇒ Object



9
10
11
# File 'lib/squasher/worker.rb', line 9

def self.process(*args)
  new(*args).process
end

Instance Method Details

#processObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/squasher/worker.rb', line 18

def process
  check!

  result = under_squash_env do
    if options.include?(:d)
      Squasher.tell(:dry_mode_finished)
      puts Render.render(:init_schema, config)
    else
      path = config.migration_file(finish_timestamp, :init_schema)
      File.open(path, 'wb') { |io| io << Render.render(:init_schema, config) }
      migrations.each { |file| FileUtils.rm(file) }
    end

    Squasher.rake("db:drop") unless Squasher.ask(:keep_database)
  end

  Squasher.clean if result && Squasher.ask(:apply_clean)
end