Class: SocialFramework::Generators::InstallMigrationsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/social_framework/install_migrations_generator.rb

Overview

Generator to add migrations in the application

Instance Method Summary collapse

Instance Method Details

#add_migrationsObject

Copy the migrations to application

Without ‘-m’ option copy all migrations, With ‘-m’ option copy specifics migrations.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/social_framework/install_migrations_generator.rb', line 16

def add_migrations
	migrations = Dir.glob(SocialFramework::Engine.config.paths["db/migrate"].first + "/*")

  if options[:migrations]
    options[:migrations].each do |migrate|
      file = "social_framework_#{migrate.pluralize}.rb"
      file = migrations.select { |m| m.include?(file) }.first
      unless file.nil? or file.empty?
        file_name = file.split("/").last
        copy_file file, "db/migrate/#{file_name}"
      else
        puts "Could not find migration: '#{migrate}'"
      end
    end
  else
    migrations.each do |migrate|
      file = migrate.split("/").last 
      copy_file migrate, "db/migrate/#{file}"
    end
  end
end