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.5.4 lib/rundock/operation_factory.rb
rundock-0.5.3 lib/rundock/operation_factory.rb
rundock-0.5.2 lib/rundock/operation_factory.rb
rundock-0.5.0 lib/rundock/operation_factory.rb
rundock-0.4.16 lib/rundock/operation_factory.rb
rundock-0.4.15 lib/rundock/operation_factory.rb
rundock-0.4.14 lib/rundock/operation_factory.rb
rundock-0.4.13 lib/rundock/operation_factory.rb
rundock-0.4.12 lib/rundock/operation_factory.rb
rundock-0.4.11 lib/rundock/operation_factory.rb
rundock-0.4.10 lib/rundock/operation_factory.rb
rundock-0.4.8 lib/rundock/operation_factory.rb
rundock-0.4.7 lib/rundock/operation_factory.rb
rundock-0.4.6 lib/rundock/operation_factory.rb
rundock-0.4.4 lib/rundock/operation_factory.rb
rundock-0.4.3 lib/rundock/operation_factory.rb
rundock-0.4.2 lib/rundock/operation_factory.rb
rundock-0.4.1 lib/rundock/operation_factory.rb
rundock-0.4.0 lib/rundock/operation_factory.rb
rundock-0.3.0 lib/rundock/operation_factory.rb