Sha256: 6631dbf709882d63c99cd6c1c0e1dc019b458bf35d888e39a1f7cc48d9fbb53b

Contents?: true

Size: 1.1 KB

Versions: 16

Compression:

Stored size: 1.1 KB

Contents

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

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

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

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

      def translated_columns
        Qbrick::Page.column_names.select { |attr| attr.end_with? "_#{I18n.default_locale}" }
      end

      def formatted_locale
        locale.underscore
      end

      def create_locale_migration_file
        migration_template('add_translation.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 = '')
        Qbrick::Page.columns_hash[key].type
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
qbrick-2.7.1 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.7 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.10 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.9 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.8 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.7 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.6 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.5 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.4 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.3 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.2 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.1 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.6.0 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.5.2 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.5.1 lib/generators/qbrick/translations/add_generator.rb
qbrick-2.5.0 lib/generators/qbrick/translations/add_generator.rb