Class: PgAssistant::Generators::FunctionGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/pg_assistant/function/function_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dir) ⇒ Object



39
40
41
# File 'lib/generators/pg_assistant/function/function_generator.rb', line 39

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

Instance Method Details

#create_function_definitionObject



17
18
19
20
21
22
23
# File 'lib/generators/pg_assistant/function/function_generator.rb', line 17

def create_function_definition
  if creating_new_function?
    create_file definition.path
  else
    copy_file previous_definition.full_path, definition.full_path
  end
end

#create_functions_directoryObject



11
12
13
14
15
# File 'lib/generators/pg_assistant/function/function_generator.rb', line 11

def create_functions_directory
  unless functions_directory_path.exist?
    empty_directory functions_directory_path
  end
end

#create_migration_fileObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/pg_assistant/function/function_generator.rb', line 25

def create_migration_file
  if creating_new_function? || destroying_initial_function?
    migration_template(
      "db/migrate/create_function.erb",
      "db/migrate/create_#{function_name}.rb"
    )
  else
    migration_template(
      "db/migrate/update_function.erb",
      "db/migrate/update_#{function_name}_to_version_#{version}.rb"
    )
  end
end