Class: ExvoGlobalize::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/exvo_globalize/install_generator.rb

Overview

Creates a new migration adding the translations table to the application and copies the exvo_globalize_i18n.js to public/javascripts/ (for Rails 3.0.x)

$ rails generate exvo_globalize:install

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.migrate_template_or_skip(source, destination) ⇒ Object

Migrates template or skips if it already exists see github.com/rails/rails/blob/master/railties/lib/rails/generators/migration.rb#L55



26
27
28
29
30
31
32
33
# File 'lib/generators/exvo_globalize/install_generator.rb', line 26

def self.migrate_template_or_skip(source, destination)
  migration_dir = File.dirname(destination)

  migration_file_name = File.basename(destination).sub(/\.rb$/, '')
  unless migration_exists?(migration_dir, migration_file_name)
    migration_template(source, destination)
  end
end

.next_migration_number(dirname) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/generators/exvo_globalize/install_generator.rb', line 16

def self.next_migration_number(dirname)
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#copy_javascript_libraryObject



43
44
45
# File 'lib/generators/exvo_globalize/install_generator.rb', line 43

def copy_javascript_library
  template '../../../../app/assets/javascripts/exvo_globalize_i18n.js', 'public/javascripts/exvo_globalize_i18n.js'
end

#create_migration_fileObject



36
37
38
39
# File 'lib/generators/exvo_globalize/install_generator.rb', line 36

def create_migration_file
  self.class.migrate_template_or_skip 'migration.rb', 'db/migrate/create_globalize_translations.rb'
  self.class.migrate_template_or_skip 'suggestions_migration.rb', 'db/migrate/create_globalize_translation_suggestions.rb'
end