Sha256: fb0def46dca3e6cb794ff4760be836f5d62edde3322757d4d8b726da7d91aba9

Contents?: true

Size: 1.1 KB

Versions: 27

Compression:

Stored size: 1.1 KB

Contents

# frozen-string-literal: true
require "rails/generators"

module Mobility
  module BackendGenerators
    class TableBackend < Mobility::BackendGenerators::Base
      source_root File.expand_path("../../templates", __FILE__)

      def create_migration_file
        if data_source_exists? && !self.class.migration_exists?(migration_dir, migration_file)
          migration_template "#{backend}_migration.rb", "db/migrate/#{migration_file}.rb"
        else
          super
        end
      end

      private

      alias_method :model_table_name, :table_name
      def table_name
        model_table_name = super
        "#{model_table_name.singularize}_translations"
      end

      def foreign_key
        "#{model_table_name.singularize}_id"
      end

      def translation_index_name
        truncate_index_name("index_#{table_name}_on_#{foreign_key}")
      end

      def translation_locale_index_name
        truncate_index_name("index_#{table_name}_on_locale")
      end

      def translation_unique_index_name
        truncate_index_name("index_#{table_name}_on_#{foreign_key}_and_locale")
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
mobility-0.5.1 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.5.0 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.4.3 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.4.2 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.4.1 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.4.0 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.3.6 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.3.5 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.3.4 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.3.3 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.3.2 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.3.1 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.3.0 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.2.3 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.2.2 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.2.1 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.2.0 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.1.20 lib/rails/generators/mobility/backend_generators/table_backend.rb
mobility-0.1.19 lib/generators/rails/mobility/backend_generators/table_backend.rb
mobility-0.1.18 lib/generators/rails/mobility/backend_generators/table_backend.rb