Module: Biovision::Migrations::ComponentMigration

Defined in:
app/lib/biovision/migrations/component_migration.rb

Overview

Mix-ins for repeated component migration parts

Instance Method Summary collapse

Instance Method Details

#componentObject

Component class



8
9
10
# File 'app/lib/biovision/migrations/component_migration.rb', line 8

def component
  @component ||= find_component
end

#downObject

Drops tables for each dependent model Removes BiovisionComponent



32
33
34
35
36
37
# File 'app/lib/biovision/migrations/component_migration.rb', line 32

def down
  component.dependent_models.reverse.each do |model|
    drop_table model.table_name if model.table_exists?
  end
  BiovisionComponent[component]&.destroy
end

#upObject

Create component tables and roles

Creates new BiovisionComponent For each dependent model, calls “create_<table_name>” method Creates roles for new component



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/lib/biovision/migrations/component_migration.rb', line 17

def up
  component.create
  component.dependent_models.each do |model|
    next if model.table_exists?

    message = "create_#{model.table_name}".to_sym
    send(message) if respond_to?(message, true)
  end
  handler = component[nil]
  handler.create_roles
  handler.seed if handler.respond_to?(:seed)
end