File: base.rb

package info (click to toggle)
ruby-specinfra 2.76.9-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,144 kB
  • sloc: ruby: 9,280; sh: 4; makefile: 3
file content (61 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
      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