Method: Train.load_transport

Defined in:
lib/train.rb

.load_transport(transport_name) ⇒ Train::Transport

Load the transport plugin indicated by name. If the plugin is not yet found in the plugin registry, it will be attempted to load from ‘train/transports/plugin_name`.

Parameters:

  • name (String)

    of the plugin

Returns:

  • (Train::Transport)

    the transport plugin



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/train.rb', line 39

def self.load_transport(transport_name)
  transport_name = transport_name.to_s
  transport_class = Train::Plugins.registry[transport_name]
  return transport_class unless transport_class.nil?

  # Try to load the transport name from the core transports...
  require 'train/transports/' + transport_name
  return Train::Plugins.registry[transport_name]
rescue LoadError => _
  begin
    # If it's not in the core transports, try loading from a train plugin gem.
    gem_name = 'train-' + transport_name
    require gem_name
    return Train::Plugins.registry[transport_name]
    # rubocop: disable Lint/HandleExceptions
  rescue LoadError => _
    # rubocop: enable Lint/HandleExceptions
    # Intentionally empty rescue - we're handling it below anyway
  end

  ex = Train::PluginLoadError.new("Can't find train plugin #{transport_name}. Please install it first.")
  ex.transport_name = transport_name
  raise ex
end