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

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