Class: OodCore::BatchConnect::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/batch_connect/factory.rb,
lib/ood_core/batch_connect/templates/vnc.rb,
lib/ood_core/batch_connect/templates/basic.rb,
lib/ood_core/batch_connect/templates/vnc_container.rb

Overview

A factory that builds a batch connect template object from a configuration.

Class Method Summary collapse

Class Method Details

.build(config) ⇒ Template

Build a batch connect template from a configuration

Parameters:

  • config (#to_h)

    configuration describing batch connect template

Options Hash (config):

  • :template (#to_s)

    The batch connect template to use

Returns:

  • (Template)

    the batch connect template object

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ood_core/batch_connect/factory.rb', line 17

def build(config)
  c = config.to_h.symbolize_keys

  template = c.fetch(:template) { raise TemplateNotSpecified, "batch connect configuration does not specify template" }.to_s

  path_to_template = "ood_core/batch_connect/templates/#{template}"
  begin
    require path_to_template
  rescue Gem::LoadError => e
    raise Gem::LoadError, "Specified '#{template}' for batch connect template, but the gem is not loaded."
  rescue LoadError => e
    raise LoadError, "Could not load '#{template}'. Make sure that that batch connect template in the configuration file is valid."
  end

  template_method = "build_#{template}"

  unless respond_to?(template_method)
    raise TemplateNotFound, "batch connect configuration specifies nonexistent #{template} template"
  end

  send(template_method, c)
end

.build_basic(config) ⇒ Object

Build the basic template from a configuration

Parameters:

  • config (#to_h)

    the configuration for the batch connect template



10
11
12
13
# File 'lib/ood_core/batch_connect/templates/basic.rb', line 10

def self.build_basic(config)
  context = config.to_h.symbolize_keys.reject { |k, _| k == :template }
  Templates::Basic.new(context)
end

.build_vnc(config) ⇒ Object

Build the VNC template from a configuration

Parameters:

  • config (#to_h)

    the configuration for the batch connect template



10
11
12
13
# File 'lib/ood_core/batch_connect/templates/vnc.rb', line 10

def self.build_vnc(config)
  context = config.to_h.symbolize_keys.reject { |k, _| k == :template }
  Templates::VNC.new(context)
end

.build_vnc_container(config) ⇒ Object

Build the VNC template from a configuration

Parameters:

  • config (#to_h)

    the configuration for the batch connect template



11
12
13
14
15
16
17
18
19
# File 'lib/ood_core/batch_connect/templates/vnc_container.rb', line 11

def self.build_vnc_container(config)
  context = config.to_h.symbolize_keys.reject { |k, _| k == :template }
  
  unless context.key?(:container_path)
    raise JobAdapterError, "You are missing the configuration 'container_path' for a vnc_container template."
  end

  Templates::VNC_Container.new(context)
end