Class: InlineFormsSchemaEdit::Generators::InstallGenerator

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

Overview

rails g inline_forms_schema_edit:install

Writes the migration for the batch pipeline's two tables (inline_forms_schema_batches + inline_forms_schema_intents). Run by the installer when an app is created with --schema-edit; existing apps adding the gem later run it by hand.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/generators/inline_forms_schema_edit/install_generator.rb', line 19

def self.next_migration_number(dirname)
  # Collision-free against migrations generated in the same second
  # (same policy as inline_forms_addto since 8.1.41).
  now = Time.now.utc.strftime("%Y%m%d%H%M%S")
  existing = Dir.glob(File.join(dirname, "*.rb")).map { |f| File.basename(f)[/\A\d+/] }.compact
  [ now, *existing.map(&:to_s) ].max.then do |highest|
    highest == now ? now : (highest.to_i + 1).to_s
  end
end

Instance Method Details

#copy_ci_workflow_exampleObject



34
35
36
37
# File 'lib/generators/inline_forms_schema_edit/install_generator.rb', line 34

def copy_ci_workflow_example
  example = File.expand_path("../../../doc/schema-apply-workflow.yml.example", __dir__)
  create_file "doc/schema-apply-workflow.yml.example", File.read(example)
end

#create_migration_fileObject



29
30
31
32
# File 'lib/generators/inline_forms_schema_edit/install_generator.rb', line 29

def create_migration_file
  migration_template "create_schema_edit_tables.rb.erb",
                     "db/migrate/create_inline_forms_schema_edit_tables.rb"
end