class PgSearch::Migration::Generator

Public Class Methods

inherited(subclass) click to toggle source
Calls superclass method
# File lib/pg_search/migration/generator.rb, line 11
def self.inherited(subclass)
  super
  subclass.source_root File.expand_path("templates", __dir__)
end

Public Instance Methods

create_migration() click to toggle source
# File lib/pg_search/migration/generator.rb, line 16
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 Instance Methods

migration_version() click to toggle source
# File lib/pg_search/migration/generator.rb, line 30
def migration_version
  if ActiveRecord::VERSION::MAJOR >= 5
    "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
  else
    ""
  end
end
read_sql_file(filename) click to toggle source
# File lib/pg_search/migration/generator.rb, line 24
def read_sql_file(filename)
  sql_directory = File.expand_path("../../../sql", __dir__)
  source_path = File.join(sql_directory, "#{filename}.sql")
  File.read(source_path).strip
end