Class: CTioga2::Data::Backends::BackendFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/data/backends/factory.rb

Overview

This class holds an instance of all the different Backend available, and features a ‘current backend’.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default) ⇒ BackendFactory

Creates a new BackendFactory



40
41
42
43
44
45
46
47
48
49
# File 'lib/ctioga2/data/backends/factory.rb', line 40

def initialize(default)
  @backends = {}
  @backend_descriptions = Backend.list_backends
  for backend in @backend_descriptions.keys
    reset_backend(backend)
    # Add commands
    @backend_descriptions[backend].create_backend_commands
  end
  @current = @backends[default]
end

Instance Attribute Details

#backendsObject

A hash name (as in Description#name) -> Backend



34
35
36
# File 'lib/ctioga2/data/backends/factory.rb', line 34

def backends
  @backends
end

#currentObject

The current Backend



37
38
39
# File 'lib/ctioga2/data/backends/factory.rb', line 37

def current
  @current
end

Instance Method Details

#reset_backend(backend) ⇒ Object

Resets the given backend to its default values.



52
53
54
# File 'lib/ctioga2/data/backends/factory.rb', line 52

def reset_backend(backend)
  @backends[backend] = @backend_descriptions[backend].instantiate
end

#set_backend_parameter_value(backend, param, value) ⇒ Object

Sets the (raw) value of the parameter of the given backend



63
64
65
66
67
# File 'lib/ctioga2/data/backends/factory.rb', line 63

def set_backend_parameter_value(backend, param, value)
  b = @backends[backend]
  # This is way too complicated !
  b.description.param_hash[param].set_value(b, value)
end

#set_current_backend(backend) ⇒ Object

Selects the current backend



57
58
59
# File 'lib/ctioga2/data/backends/factory.rb', line 57

def set_current_backend(backend)
  @current = @backends[backend]
end