Sha256: 33a831d8c852736c891b146a53d59984293a41bc51e1714ffe525b280290e713

Contents?: true

Size: 893 Bytes

Versions: 61

Compression:

Stored size: 893 Bytes

Contents

module Tenon
  module Generators
    class I18nMigrationsGenerator < Rails::Generators::Base
      source_root File.expand_path('../templates', __FILE__)

      def copy_files
        ActiveRecord::Migration.check_pending!
        fail 'You have not defined any languages in Tenon.config.languages' if languages.empty?
        timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
        template('migration.rb', File.join('db/migrate', "#{timestamp}_add_i18n_fields_#{file_hash.downcase}.rb"))
      end

      private

      def yaml
        @yaml ||= YAML.load_file(File.join(Rails.root, 'config', 'i18n_fields.yml')).symbolize_keys
      end

      def languages
        Tenon.config.languages.try(:values) || []
      end

      def tables
        yaml[:tables]
      end

      def file_hash
        require 'digest/md5'
        Digest::MD5.hexdigest(yaml.to_s)
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
tenon-1.1.8 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-1.1.7 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-1.1.6 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.1.0 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.0.8 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.0.7 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.0.6 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.0.5 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.0.4 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.0.3 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.0.2 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.0.1 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-2.0.0 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-1.1.5 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-1.1.4 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-1.1.3 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-1.1.2 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-1.1.1 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-1.0.76 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
tenon-1.0.75 lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb