Sha256: 4e37e1282586934775bfdef72d795727c2e844207bafa950aeaf47de124ee49b

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 KB

Contents

require "rails/generators"
require "rails/generators/active_record"
require_relative "./active_record_migration_compatibility"

module Mobility
  class InstallGenerator < ::Rails::Generators::Base
    include ::Rails::Generators::Migration
    include ::Mobility::ActiveRecordMigrationCompatibility

    desc "Generates migrations to add translations tables."

    source_root File.expand_path("../templates", __FILE__)
    class_option(
      :without_tables,
      type: :boolean,
      default: false,
      desc: "Skip creating translations tables."
    )

    def create_migration_file
      add_mobility_migration("create_text_translations")   unless options.without_tables?
      add_mobility_migration("create_string_translations") unless options.without_tables?
    end

    def create_initializer
      copy_file "initializer.rb", "config/initializers/mobility.rb"
    end

    def self.next_migration_number(dirname)
      ::ActiveRecord::Generators::Base.next_migration_number(dirname)
    end

    protected

    def add_mobility_migration(template)
      migration_dir = File.expand_path("db/migrate")
      if self.class.migration_exists?(migration_dir, template)
        ::Kernel.warn "Migration already exists: #{template}"
      else
        migration_template "#{template}.rb", "db/migrate/#{template}.rb"
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mobility-0.4.3 lib/rails/generators/mobility/install_generator.rb
mobility-0.4.2 lib/rails/generators/mobility/install_generator.rb
mobility-0.4.1 lib/rails/generators/mobility/install_generator.rb
mobility-0.4.0 lib/rails/generators/mobility/install_generator.rb
mobility-0.3.6 lib/rails/generators/mobility/install_generator.rb
mobility-0.3.5 lib/rails/generators/mobility/install_generator.rb
mobility-0.3.4 lib/rails/generators/mobility/install_generator.rb
mobility-0.3.3 lib/rails/generators/mobility/install_generator.rb
mobility-0.3.2 lib/rails/generators/mobility/install_generator.rb
mobility-0.3.1 lib/rails/generators/mobility/install_generator.rb
mobility-0.3.0 lib/rails/generators/mobility/install_generator.rb
mobility-0.2.3 lib/rails/generators/mobility/install_generator.rb
mobility-0.2.2 lib/rails/generators/mobility/install_generator.rb
mobility-0.2.1 lib/rails/generators/mobility/install_generator.rb
mobility-0.2.0 lib/rails/generators/mobility/install_generator.rb
mobility-0.1.20 lib/rails/generators/mobility/install_generator.rb