Sha256: 4b97c43275e942c70e83113a8280d85df2a2ddecf026e6353fd7142c8afcb6a9

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

class MigrationGenerator < Merb::GeneratorBase
  attr_reader :model_attributes, :model_class_name, :model_file_name, :table_name
  
  def initialize(args, runtime_args = {})
    @base =                 File.dirname(__FILE__)
    super
    @model_file_name  =      args.shift.snake_case
    @table_name       =      @model_file_name.pluralize
    @model_class_name =     @model_file_name.to_const_string
    @model_attributes =     Hash[*(args.map{|a| a.split(":") }.flatten)]
  end
  
  def manifest
    record do |m|
      @m = m
      
      m.directory "schema/migrations"
      
      current_migration_number = Dir[Dir.pwd+'/schema/migrations/*'].map{|f| File.basename(f) =~ /^(\d+)/; $1}.max
      @migration_file_name = format("%03d_%s", (current_migration_number.to_i+1), model_file_name) + "_migration"
    
      @assigns = {  :model_file_name  => model_file_name, 
                    :model_attributes => model_attributes,
                    :model_class_name => model_class_name,
                    :table_name       => table_name,
                    :migration_file_name => @migration_file_name
                  }
      copy_dirs
      copy_files
    end
  end
  
  protected
  def banner
    <<-EOS.split("\n").map{|x| x.strip}.join("\n")
      Creates an Active Record Migration stub..

      USAGE: #{spec.name}"
    EOS
  end
      
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
merb_activerecord-0.9.2 activerecord_generators/migration/migration_generator.rb
merb_activerecord-0.9.3 activerecord_generators/migration/migration_generator.rb