Sha256: bec1814505af3bc522a14b98c83160f72be96585a2164076c0c53d2461ebdbcc

Contents?: true

Size: 1006 Bytes

Versions: 5

Compression:

Stored size: 1006 Bytes

Contents

module Zodiac
  class MigrationGenerator < Rails::Generators::Base
    source_root File.expand_path('../templates', __FILE__)
    argument :model_name, type: :string
    argument :sign_attribute, type: :string, default: 'zodiac_sign_id'
    
    def copy_files
      template template_name, "db/migrate/#{migration_filename}.rb"
    end
    
  private
    def template_name
      if Rails.version < '3.1'
        'migration30.rb.erb'
      else
        'migration31.rb.erb'
      end
    end
    
    def date_prefix
      Time.now.strftime('%Y%m%d%H%M%S') # filename prefix like 20110922205139
    end
    
    def migration_filename
      "#{date_prefix}_add_#{sign_attribute}_to_#{table_name}"
    end
    
    def migration_classname
      "Add#{sign_attribute.camelcase}To#{model_name.gsub('::', '').camelcase.pluralize}"
    end
    
    def model_classname
      model_name.camelcase.singularize
    end
    
    def table_name
      model_name.underscore.gsub('/', '_').pluralize
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
zodiac-0.2.10 lib/generators/zodiac/migration/migration_generator.rb
zodiac-0.2.9 lib/generators/zodiac/migration/migration_generator.rb
zodiac-0.2.8 lib/generators/zodiac/migration/migration_generator.rb
zodiac-0.2.7 lib/generators/zodiac/migration/migration_generator.rb
zodiac-0.2.6 lib/generators/zodiac/migration/migration_generator.rb