Sha256: 7c6dbb590c710023455b6b8901427394cb6566e6751e7fc692deac3db6c59541

Contents?: true

Size: 1.2 KB

Versions: 54

Compression:

Stored size: 1.2 KB

Contents

require 'singleton'
require 'specinfra/command_result'

module Specinfra
  module Backend
    class Base
      def self.instance
        @instance ||= self.new
      end

      def self.clear
        @instance = nil
      end

      def initialize(config = {})
        @config = config
        @example = nil
      end

      def get_config(key)
        @config[key] || Specinfra.configuration.send(key)
      end

      def set_config(key, value)
        @config[key] = value
      end

      def os_info
        return @os_info if @os_info

        Specinfra::Helper::DetectOs.subclasses.each do |klass|
          if @os_info = klass.new(self).detect
            @os_info[:arch] ||= self.run_command('uname -m').stdout.strip
            return @os_info
          end
        end

        raise NotImplementedError, 'OS detection failed.'
      end

      def command
        CommandFactory.new(os_info)
      end

      def host_inventory
        @inventory ||= HostInventory.new(self)
      end

      def set_example(e)
        @example = e
      end

      def stdout_handler=(block)
        @stdout_handler = block
      end

      def stderr_handler=(block)
        @stderr_handler = block
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
specinfra-2.91.0 lib/specinfra/backend/base.rb
specinfra-2.90.1 lib/specinfra/backend/base.rb
specinfra-2.90.0 lib/specinfra/backend/base.rb
specinfra-2.89.0 lib/specinfra/backend/base.rb
specinfra-2.88.2 lib/specinfra/backend/base.rb
specinfra-2.88.1 lib/specinfra/backend/base.rb
specinfra-2.88.0 lib/specinfra/backend/base.rb
specinfra-2.87.2 lib/specinfra/backend/base.rb
specinfra-2.87.1 lib/specinfra/backend/base.rb
specinfra-2.87.0 lib/specinfra/backend/base.rb
specinfra-2.86.0 lib/specinfra/backend/base.rb
specinfra-2.85.1 lib/specinfra/backend/base.rb
specinfra-2.85.0 lib/specinfra/backend/base.rb
specinfra-2.84.1 lib/specinfra/backend/base.rb
specinfra-2.84.0 lib/specinfra/backend/base.rb
specinfra-2.83.4 lib/specinfra/backend/base.rb
specinfra-2.83.3 lib/specinfra/backend/base.rb
specinfra-2.83.2 lib/specinfra/backend/base.rb
specinfra-2.83.1 lib/specinfra/backend/base.rb
specinfra-2.83.0 lib/specinfra/backend/base.rb