Sha256: 8b659474c7dd5123ffc86fd4c516cb7399dec16f618b3aa4caa92948d6b001d9

Contents?: true

Size: 1.18 KB

Versions: 17

Compression:

Stored size: 1.18 KB

Contents

require 'specinfra/helper/detect_os'

module Specinfra::Helper::Os
  def os
    property[:os_by_host] = {} if ! property[:os_by_host]
    host_port = current_host_and_port

    if property[:os_by_host][host_port]
      os_by_host = property[:os_by_host][host_port]
    else
      # Set command object explicitly to avoid `stack too deep`
      os_by_host = detect_os
      property[:os_by_host][host_port] = os_by_host
    end
    os_by_host
  end

  private

  # put this in a module for better reuse
  def current_host_and_port
    if Specinfra.configuration.ssh
      "#{Specinfra.configuration.ssh.host}:#{Specinfra.configuration.ssh.options[:port]}"
    elsif Specinfra.configuration.ssh_options
          
      "#{Specinfra.configuration.host}:#{Specinfra.configuration.ssh_options[:port]}"
    else
      "#{Specinfra.configuration.host}:0"
    end
  end

  def run_command(cmd)
    Specinfra.backend.run_command(cmd)
  end

  def detect_os
    return Specinfra.configuration.os if Specinfra.configuration.os
    Specinfra::Helper::DetectOs.subclasses.each do |c|
      res = c.detect
      if res
        res[:arch] ||= run_command('uname -m').stdout.strip
        return res
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
specinfra-2.0.0.beta31 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta30 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta29 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta28 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta27 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta26 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta25 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta24 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta23 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta22 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta21 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta20 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta19 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta18 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta17 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta16 lib/specinfra/helper/os.rb
specinfra-2.0.0.beta15 lib/specinfra/helper/os.rb