Sha256: 8bad03f73cc807ef3936da7b8c2dfc8c68eb5cefa462b896ba3e80a7ae979f2d

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

require "rails/generators"
require "rails/generators/active_record"

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

    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
      create_file(
        "config/initializers/mobility.rb",
        "Mobility.config.default_backend = :key_value"
      )
    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

5 entries across 5 versions & 1 rubygems

Version Path
mobility-0.1.4 lib/generators/mobility/install_generator.rb
mobility-0.1.3 lib/generators/mobility/install_generator.rb
mobility-0.1.2 lib/generators/mobility/install_generator.rb
mobility-0.1.1 lib/generators/mobility/install_generator.rb
mobility-0.1.0 lib/generators/mobility/install_generator.rb