Class: Container::Backup::StepFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/container/step_factory.rb

Direct Known Subclasses

Databases

Class Method Summary collapse

Class Method Details

.build(container, directory, backup, type, params) ⇒ Object



29
30
31
# File 'lib/container/step_factory.rb', line 29

def self.build(container, directory, backup, type, params)
  StepFactory.get_class(type).new(container, directory, backup, params)
end

.generate(container, directory, backup, actions) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/container/step_factory.rb', line 13

def self.generate(container, directory, backup, actions)
  actions.map do |a|
    a.map do |type, steps|
      steps.map do |param|
        if Object.const_get(['Container', 'Backup', type.capitalize].join('::')).superclass == Container::Backup::StepFactory
          (param.is_a?(String) ? {param => {}} : param).map do |type, param|
            StepFactory.build(container, directory, backup, type, param)
          end
        else
          StepFactory.build(container, directory, backup, type, param)
        end
      end
    end
  end.flatten
end

.get_class(type) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/container/step_factory.rb', line 4

def self.get_class(type)
  klass = Object.const_get(['Container', 'Backup', type.capitalize].join('::'))
  if klass.ancestors.include? Container::Backup::Step
    klass
  else
    raise 'Unknown step for #{klass}'
  end
end