Class: DatabaseResetter

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

Instance Method Summary collapse

Constructor Details

#initialize(options = { }) ⇒ DatabaseResetter

Returns a new instance of DatabaseResetter.



4
5
6
7
8
9
# File 'lib/database_resetter.rb', line 4

def initialize(options = { })
  # NOTE There are no features/specs to prove the defaults are present
  @environment      = options.fetch(:environment, ENV["RAILS_ENV"])
  @command_pattern  = options.fetch(:command_pattern, "rake db:reset RAILS_ENV=%ENV%")
  @files_to_watch   = "#{options.fetch(:migration_directory, "db/migrate")}/**/*.rb"
end

Instance Method Details

#reset_if_requiredObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/database_resetter.rb', line 11

def reset_if_required
  if migration_dir.empty?
    puts "*** No migrations"
    return
  end

  if migrations_changed_since_last_database_reset?
    reset
  else
    puts "*** Skipping database reset (migrations not changed since last run)"
    puts "*** Run `#{reset_command}` if necessary, or touch a migration"
  end
end