Module: RSpec::Rails::Migration

Includes:
App::Dirs
Included in:
FileMatchers::GenerateMigration
Defined in:
lib/rspec_for_generators/rails_helpers/rails_migration.rb

Instance Method Summary collapse

Methods included from App::Dirs

#app_dir, #config_dir, #controller_dir, #db_dir, #helper_dir, #initializer_dir, #javascript_dir, #locale_dir, #migration_dir, #model_dir, #stylesheet_dir, #view_dir

Instance Method Details

#create_migration(number, name, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/rspec_for_generators/rails_helpers/rails_migration.rb', line 5

def create_migration number, name, &block      
  file = migration_file_name(number, name)
  unless File.exist?(file)    
    FileUtils.mkdir_p File.dirname(file)
    File.open(file, 'w') do |f|  
      f.puts file_content(name)
      yield f if block_given?
    end
  end
end

#migration_file_name(number, name) ⇒ Object



32
33
34
# File 'lib/rspec_for_generators/rails_helpers/rails_migration.rb', line 32

def migration_file_name number, name
  File.join(migration_dir, "#{number}_#{name}.rb")
end

#remove_migration(name) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/rspec_for_generators/rails_helpers/rails_migration.rb', line 16

def remove_migration name
  migrations = Dir.glob("#{migration_dir}/[0-9]*_*.rb")
  migration_file = if !migrations.empty? 
    migrations.grep(/\d+_#{name}\.rb$/).first 
  else 
    false
  end
  FileUtils.rm_f(migration_file) if migration_file
end

#remove_migrations(*names) ⇒ Object



26
27
28
29
30
# File 'lib/rspec_for_generators/rails_helpers/rails_migration.rb', line 26

def remove_migrations *names
  names.each do |name| 
    remove_migration name
  end
end