Sha256: c95d7cd99a6e83c7ddf4d796346b0403c75fde1b56419b357ba04848ab8a2824

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

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

module Kuhsaft
  module Translations
    class Add < Rails::Generators::Base
      include Rails::Generators::Migration

      source_root(File.join(Kuhsaft::Engine.root, '/lib/templates/kuhsaft/translations'))
      argument :locale, type: :string

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

      def translated_columns
        Kuhsaft::Page.column_names.select { |attr| attr.include?("_#{I18n.default_locale}") }
      end

      def formatted_locale
        locale.underscore
      end

      def create_locale_migration_file
        migration_template('add_translation.html.erb',
                           Rails.root.join('db', 'migrate', "add_#{formatted_locale}_translation.rb"))
      end

      private

      def get_attribute(attribute_name = '')
        attribute_name.gsub("_#{I18n.default_locale}", "_#{formatted_locale}")
      end

      def get_type(key = '')
        Kuhsaft::Page.columns_hash[key].type
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kuhsaft-2.4.1 lib/generators/kuhsaft/translations/add_generator.rb
kuhsaft-2.4.0 lib/generators/kuhsaft/translations/add_generator.rb
kuhsaft-2.3.6 lib/generators/kuhsaft/translations/add_generator.rb
kuhsaft-2.3.5 lib/generators/kuhsaft/translations/add_generator.rb
kuhsaft-2.3.4 lib/generators/kuhsaft/translations/add_generator.rb
kuhsaft-2.3.3 lib/generators/kuhsaft/translations/add_generator.rb
kuhsaft-2.3.2 lib/generators/kuhsaft/translations/add_generator.rb
kuhsaft-2.3.1 lib/generators/kuhsaft/translations/add_generator.rb
kuhsaft-2.3.0 lib/generators/kuhsaft/translations/add_generator.rb