Sha256: a508b6af4d7b63f4fb944730423ecbaddfe52414cd6ca5bffa59a1f6f4baf112

Contents?: true

Size: 959 Bytes

Versions: 3

Compression:

Stored size: 959 Bytes

Contents

require 'rails/generators'
require 'rails/generators/active_record'

class EavMigrationGenerator < ActiveRecord::Generators::Base

  source_root File.expand_path "../templates", __FILE__
  # small hack to override NamedBase displaying NAME
  argument :name, :required => true, :type => :string, :banner => "<ModelName>"
  argument :hash_name, :required => true, :type => :string, :banner => "<hash_name>"
  argument :custom_table_name, :required => false, :type => :string, :banner => "table_name"

  def create_eav_migration
    p name
    migration_template "eav_migration.erb", "db/migrate/#{migration_file_name}.rb"
  end

  def migration_file_name
    "create_" + table_name
  end

  def migration_name
    migration_file_name.camelize
  end

  def table_name
    custom_table_name || "#{name}_#{hash_name}".underscore.gsub(/\//, '_')
  end

  def model_name
    name
  end

  def model_association_name
    model_name.underscore.gsub(/\//,'_')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eav_hashes-1.1.0 lib/generators/eav_migration/eav_migration.rb
eav_hashes-1.0.3 lib/generators/eav_migration/eav_migration.rb
eav_hashes-1.0.2 lib/generators/eav_migration/eav_migration.rb