Module: Rails3Generators::MigrationHelper::ClassMethods

Defined in:
lib/generators/helpers/migration_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_migration_number(dirname) ⇒ Object

:nodoc:



18
19
20
21
22
# File 'lib/generators/helpers/migration_helper.rb', line 18

def current_migration_number(dirname) #:nodoc:
  migration_lookup_at(dirname).collect do |file|
    File.basename(file).split("_").first.to_i
  end.max.to_i
end

#migration_exists?(dirname, file_name) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


14
15
16
# File 'lib/generators/helpers/migration_helper.rb', line 14

def migration_exists?(dirname, file_name) #:nodoc:
  migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
end

#migration_lookup_at(dirname) ⇒ Object

:nodoc:



10
11
12
# File 'lib/generators/helpers/migration_helper.rb', line 10

def migration_lookup_at(dirname) #:nodoc:
  Dir.glob("#{dirname}/[0-9]*_*.rb")
end

#next_migration_number(dirname) ⇒ Object

:nodoc:



24
25
26
27
28
29
30
# File 'lib/generators/helpers/migration_helper.rb', line 24

def next_migration_number(dirname) #:nodoc:
  orm = Rails.configuration.generators.options[:rails][:orm]
  require "rails/generators/#{orm}"
  "#{orm.to_s.camelize}::Generators::Base".constantize.next_migration_number(dirname)         
rescue
  raise NotImplementedError
end