Sha256: fb729fcc93f9d70b9a166b7ff2f0bb5e9cdfe623459e955f088f83793b15bc13

Contents?: true

Size: 696 Bytes

Versions: 11

Compression:

Stored size: 696 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}"
      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

11 entries across 11 versions & 1 rubygems

Version Path
rundock-0.2.10 lib/rundock/operation_factory.rb
rundock-0.2.9 lib/rundock/operation_factory.rb
rundock-0.2.8 lib/rundock/operation_factory.rb
rundock-0.2.7 lib/rundock/operation_factory.rb
rundock-0.2.6 lib/rundock/operation_factory.rb
rundock-0.2.5 lib/rundock/operation_factory.rb
rundock-0.2.4 lib/rundock/operation_factory.rb
rundock-0.2.3 lib/rundock/operation_factory.rb
rundock-0.2.2 lib/rundock/operation_factory.rb
rundock-0.2.0 lib/rundock/operation_factory.rb
rundock-0.1.0 lib/rundock/operation_factory.rb