Class: Squasher::Worker

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ Worker

Returns a new instance of Worker.



11
12
13
# File 'lib/squasher/worker.rb', line 11

def initialize(date)
  @date = date
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



5
6
7
# File 'lib/squasher/worker.rb', line 5

def date
  @date
end

Class Method Details

.process(*args) ⇒ Object



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

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

Instance Method Details

#processObject



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

def process
  check!

  result = under_squash_env do
    if Squasher.config.set?(:dry)
      Squasher.tell(:dry_mode_finished)
      Squasher.print(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