Sha256: 9a9d09930a391c2eff92198980ae87eff02d5982e0beaae6f19283208f3724a8

Contents?: true

Size: 998 Bytes

Versions: 3

Compression:

Stored size: 998 Bytes

Contents

require 'active_record'
require 'rails/generators/base'

module PgSearch
  module Migration
    class Generator < Rails::Generators::Base
      Rails::Generators.hide_namespace namespace

      def self.inherited(subclass)
        super
        subclass.source_root File.expand_path('../templates', __FILE__)
      end

      def create_migration
        now = Time.now.utc
        filename = "#{now.strftime('%Y%m%d%H%M%S')}_#{migration_name}.rb"
        template "#{migration_name}.rb.erb", "db/migrate/#{filename}", migration_version
      end

      private

      def read_sql_file(filename)
        sql_directory = File.expand_path('../../../../sql', __FILE__)
        source_path = File.join(sql_directory, "#{filename}.sql")
        File.read(source_path).strip
      end

      def migration_version
        if ActiveRecord::VERSION::MAJOR >= 5
          "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
        else
          ""
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pg_search-2.1.2 lib/pg_search/migration/generator.rb
pg_search-2.1.1 lib/pg_search/migration/generator.rb
pg_search-2.1.0 lib/pg_search/migration/generator.rb