Class: Hoardable::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/hoardable/install_generator.rb

Overview

Generates an initializer file for Hoardable configuration and a migration with a PostgreSQL function.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dir) ⇒ Object



46
47
48
# File 'lib/generators/hoardable/install_generator.rb', line 46

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

Instance Method Details

#create_functionsObject



26
27
28
29
30
31
32
33
# File 'lib/generators/hoardable/install_generator.rb', line 26

def create_functions
  Dir
    .glob(File.join(__dir__, "functions", "*.sql"))
    .each do |file_path|
      file_name = file_path.match(%r{([^/]+)\.sql})[1]
      template file_path, "db/functions/#{file_name}_v01.sql"
    end
end

#create_initializer_fileObject



12
13
14
15
16
17
18
19
20
# File 'lib/generators/hoardable/install_generator.rb', line 12

def create_initializer_file
  create_file("config/initializers/hoardable.rb", <<~TEXT)
    # Hoardable configuration defaults are below. Learn more at https://github.com/waymondo/hoardable#configuration
    #
    # Hoardable.enabled = true
    # Hoardable.version_updates = true
    # Hoardable.save_trash = true
  TEXT
end

#create_migration_fileObject



22
23
24
# File 'lib/generators/hoardable/install_generator.rb', line 22

def create_migration_file
  migration_template "install.rb.erb", "db/migrate/install_hoardable.rb"
end