Module: SeedMigrator::UpdateClassLoader

Included in:
SeedMigrator, Seeds
Defined in:
lib/seed_migrator/update_class_loader.rb

Overview

Machinery to load the actual data update classes

Instance Method Summary collapse

Instance Method Details

#get_update_class(root_path, update_name) ⇒ ::Class

Loads the class corresponding to the given update name from the given

file system path.

Parameters:

  • root_path (String|Pathname|Symbol)
  • update_name (String|Symbol)

Returns:

  • (::Class)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/seed_migrator/update_class_loader.rb', line 12

def get_update_class(root_path, update_name)
  update = strip_seq_prefix(update_name.to_s)
  file_name = find_file(root_path, update)
  if file_name
    file_name = File.basename(file_name, '.rb')
    if root_path.to_s.ends_with?('/')
      require "#{root_path}#{file_name}"
    else
      require "#{root_path}/#{file_name}"
    end
    update.camelize.constantize
  else
    raise LoadError, "Unable to find file for update #{update_name} in #{root_path}"
  end
end