Module: AuthAssist::MigrationHelper

Includes:
CodeRefactor, Rails::Generators::Migration
Included in:
Generators::ClearGenerator, Generators::ConfigGenerator, RoleMigrations::Base
Defined in:
lib/generators/migration_helper.rb,
lib/generators/auth_code_refactor.rb,
lib/generators/reverse_migrations.rb

Defined Under Namespace

Modules: ClassMethods, CodeRefactor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CodeRefactor

#clear_user_relations, #erase_in_user, #has_role_assignments, #has_roles, #has_roles_through_assignments, #insert_user_relation, #remove_user_relation, #role_assignment_file_content, #role_file_content, #write_model_file

Class Method Details

.included(base) ⇒ Object

:nodoc:



32
33
34
35
# File 'lib/generators/migration_helper.rb', line 32

def self.included(base) #:nodoc: 
  puts "MigrationHelper included by #{base}"
  base.extend ClassMethods      
end

Instance Method Details

#copy_migration(name, new_name, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/reverse_migrations.rb', line 26

def copy_migration(name, new_name, &block) 
  # create empty new migration
  migration new_name
  new_migration = find_migration(name)          
  find_migration(name) do |mig|
    FileUtils.cp mig, new_migration
  end
  return block.call(new_migration) if block
  new_migration      
end

#file_reverse(file, str1, str2) ⇒ Object



41
42
43
44
45
# File 'lib/generators/reverse_migrations.rb', line 41

def file_reverse(file, str1, str2) 
  # use thor action          
  file.replace str1, str2
  file.replace str2, str1
end

#find_migration(name, &block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/generators/reverse_migrations.rb', line 14

def find_migration(name, &block)    
  FileUtils.cd migration_dir do          
    f = FileList['*.rb'].reject{|f| (f =~ /#{Regexp.escape(name)}/) == nil }.first
    return block.call(f) if block
  end
  f
end

#migration(options) ⇒ Object



38
39
40
41
# File 'lib/generators/migration_helper.rb', line 38

def migration(options)   
  # migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"      
  run "rails g migration #{options}"
end

#migration_dirObject



3
4
5
# File 'lib/generators/reverse_migrations.rb', line 3

def migration_dir
  File.join(Rails.root, 'db/migrate')          
end

#migration_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/generators/reverse_migrations.rb', line 22

def migration_exists?(name)
  find_migration(name)      
end

#reverse_migration(mig_name) ⇒ Object



7
8
9
10
11
12
# File 'lib/generators/reverse_migrations.rb', line 7

def reverse_migration(mig_name)
  if migration_exists?(mig_name)
    new_migration = copy_migration(mig_name, "reverse_#{strategy_name}")
    reverse_migration_method_names(new_migration)
  end
end

#reverse_migration_methods(new_migration) ⇒ Object



37
38
39
# File 'lib/generators/reverse_migrations.rb', line 37

def reverse_migration_methods(new_migration) 
  file_swap_content(new_migration, 'self.up', 'self.down')
end