Sha256: 82f57c33e473ced6b644b6c9a91a9f4e8b1e99e4edc44dbb4bc3040d1acef79c

Contents?: true

Size: 748 Bytes

Versions: 21

Compression:

Stored size: 748 Bytes

Contents

module Rundock
  class OperationFactory
    OperationNotImplementedError = Class.new(NotImplementedError)

    def self.instance(type)
      self.new(type)
    end

    def initialize(type)
      @type = type
    end

    def create(instruction, attributes)
      klass = "Rundock::Operation::#{@type.to_s.to_camel_case}"
      Logger.debug("initialize #{klass} operation")
      raise OperationNotImplementedError unless Rundock::Operation::Base.subclasses.map(&:to_s).include?(klass)

      obj = nil
      klass.split('::').map do |k|
        if obj.nil?
          obj = Kernel.const_get(k)
        else
          obj = obj.const_get(k)
        end
      end

      operation = obj.new(instruction, attributes)
      operation
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rundock-0.2.11 lib/rundock/operation_factory.rb