Class: AutomateIt::PlatformManager::Struct

Inherits:
BaseDriver show all
Defined in:
lib/automateit/platform_manager/struct.rb

Overview

PlatformManager::Struct

A simple PlatformManager driver that queries a hash for results. Although not useful on its own, it’s inherited by other drivers that provide platform-specific methods to query the system.

Direct Known Subclasses

Darwin, Uname, Windows

Constant Summary

Constants inherited from AutomateIt::Plugin::Driver

AutomateIt::Plugin::Driver::BASE_DRIVER_NAME

Constants included from Constants

Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE

Instance Attribute Summary collapse

Attributes inherited from AutomateIt::Plugin::Driver

#manager

Attributes inherited from Common

#interpreter

Instance Method Summary collapse

Methods inherited from AutomateIt::Plugin::Driver

abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token

Methods inherited from AutomateIt::Plugin::Base

#token, token

Methods inherited from Common

#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #superuser?, #writing, #writing=, #writing?

Constructor Details

This class inherits a constructor from AutomateIt::Common

Instance Attribute Details

#key_aliasesObject

Hash mapping of keys that have many common names, e.g., “release” and “version”



10
11
12
# File 'lib/automateit/platform_manager/struct.rb', line 10

def key_aliases
  @key_aliases
end

Instance Method Details

#query(search) ⇒ Object

See PlatformManager#query



36
37
38
39
40
41
42
43
# File 'lib/automateit/platform_manager/struct.rb', line 36

def query(search)
  result = ""
  for key in search.to_s.split(/#/)
    result << "_" unless result.empty?
    result << _query_key(key)
  end
  result
end

#setup(opts = {}) ⇒ Object

Options:

  • :struct – The hash to use for queries.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/automateit/platform_manager/struct.rb', line 18

def setup(opts={})
  super(opts)

  @@struct_cache ||= {}

  if opts[:struct]
    @struct = opts[:struct]
  else
    @struct ||= {}
  end

  # Generate bi-directional map
  @key_aliases ||= @@key_aliases ||= {
    :version => :release,
  }.inject({}){|s,v| s[v[0]] = v[1]; s[v[1]] = v[0]; s}
end

#single_vendor?Boolean

See PlatformManager#single_vendor?

Returns:

  • (Boolean)


60
61
62
# File 'lib/automateit/platform_manager/struct.rb', line 60

def single_vendor?
  return false
end

#suitability(method, *args) ⇒ Object

:nodoc:



12
13
14
# File 'lib/automateit/platform_manager/struct.rb', line 12

def suitability(method, *args) # :nodoc:
  return 1
end

#tagsObject

See PlatformManager#tags



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/automateit/platform_manager/struct.rb', line 65

def tags
  results = []
  for key in %w(os arch distro os#arch)
    results << query(key) rescue IndexError
  end

  release_query = \
    if single_vendor?
      "os#release"     # E.g. windows_xp
    else
      "distro#release" # E.g. ubuntu_6.06
    end
  results << query(release_query) rescue IndexError
  return results
end