Module: Rails3::Assist::Artifact::Migration::FileName

Includes:
Migration::Assist::ClassMethods
Included in:
Rails3::Assist::Artifact::Migration, Rails3::Assist::Artifact::Migration
Defined in:
lib/rails3_artifactor/artifact/file_name/migration.rb

Defined Under Namespace

Classes: FindError

Constant Summary collapse

DIR =
Rails3::Assist::Artifact::Directory

Instance Method Summary collapse

Instance Method Details

#find_migration(name, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rails3_artifactor/artifact/file_name/migration.rb', line 28

def find_migration name, options={}
  root_path = options[:root_path]        
     
  migration_dir_name = File.expand_path(DIR.migration_dir options)

  migration_find_expr = "#{migration_dir_name}/[0-9]*_*.rb"
  migrations = Dir.glob(migration_find_expr)

  find_err = FindError.new migration_find_expr

  return find_err if migrations.empty?  

  migration_find_expr = /\d+_#{name}\.rb$/
  find_err.find_expr = migration_find_expr
    
  matching_migrations = migrations.grep_it(migration_find_expr)

  return find_err if matching_migrations.empty?

  migration_file = (options[:last]) ? matching_migrations.last : matching_migrations.first
end

#migration_file_name(name, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rails3_artifactor/artifact/file_name/migration.rb', line 19

def migration_file_name name, options={}
  number = options[:number]              

  migration_dir_name = File.expand_path(DIR.migration_dir options)
        
  number = next_migration_number(migration_dir_name) if !number      
  File.join(migration_dir_name, "#{number}_#{name}.rb")      
end