class Fx::Generators::FunctionGenerator
@api private
Public Class Methods
next_migration_number(dir)
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 39 def self.next_migration_number(dir) ::ActiveRecord::Generators::Base.next_migration_number(dir) end
Public Instance Methods
activerecord_migration_class()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 62 def activerecord_migration_class if ActiveRecord::Migration.respond_to?(:current_version) "ActiveRecord::Migration[5.0]" else "ActiveRecord::Migration" end end
create_function_definition()
click to toggle source
# File lib/generators/fx/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_directory()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 11 def create_functions_directory unless function_definition_path.exist? empty_directory(function_definition_path) end end
create_migration_file()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 25 def create_migration_file if updating_existing_function? migration_template( "db/migrate/update_function.erb", "db/migrate/update_function_#{file_name}_to_version_#{version}.rb", ) else migration_template( "db/migrate/create_function.erb", "db/migrate/create_function_#{file_name}.rb", ) end end
formatted_name()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 70 def formatted_name if singular_name.include?(".") "\"#{singular_name}\"" else ":#{singular_name}" end end
migration_class_name()
click to toggle source
Calls superclass method
# File lib/generators/fx/function/function_generator.rb, line 54 def migration_class_name if updating_existing_function? "UpdateFunction#{class_name}ToVersion#{version}" else super end end
previous_version()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 44 def previous_version @_previous_version ||= Dir.entries(function_definition_path). map { |name| version_regex.match(name).try(:[], "version").to_i }. max end
version()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 50 def version @_version ||= previous_version.next end
Private Instance Methods
creating_new_function?()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 93 def creating_new_function? previous_version == 0 end
definition()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 97 def definition Fx::Definition.new(name: file_name, version: version) end
function_definition_path()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 81 def function_definition_path @_function_definition_path ||= Rails.root.join(*%w(db functions)) end
previous_definition()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 101 def previous_definition Fx::Definition.new(name: file_name, version: previous_version) end
updating_existing_function?()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 89 def updating_existing_function? previous_version > 0 end
version_regex()
click to toggle source
# File lib/generators/fx/function/function_generator.rb, line 85 def version_regex /\A#{file_name}_v(?<version>\d+)\.sql\z/ end