⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globalize_generator.rb

📁 A Hotel Management System based on Ruby on Rails.
💻 RB
字号:
require 'zlib'
require 'pathname'

class GlobalizeGenerator < MigrationGenerator
  def initialize(runtime_args, runtime_options = {})
    arg = runtime_args.first
    @tiny = arg && arg.downcase == 'tiny'
    super([ "globalize_migration" ] + runtime_args, runtime_options)
  end

  def banner
    "Usage: script/generate globalize [tiny]\n" +
    '  Specify "tiny" to generate a compact version of the data files (major languages only).'
  end

  def inflate_schema
    deflated_name = @tiny ? 'tiny_migration.rb.gz' : 'migration.rb.gz'
    inflated_path = source_path('migration.rb')
    deflated_path = source_path(deflated_name)

    return if File.exist?(inflated_path) && !File.exist?(deflated_path)
    return if !File.exist?(deflated_path)

    File.open(inflated_path, 'w') do |f|
      Zlib::GzipReader.open(deflated_path) do |gzip|
        gzip.each do |line|
          line.chomp!
          f.puts line
        end
      end
    end
  end

  def manifest
    record do |m|
      m.directory 'db/migrate'
      m.inflate_schema
      m.migration_template 'migration.rb', 'db/migrate'
    end
  end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -