Class: Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/inspector.rb

Overview

This is the base class for all the “inspect” plugin classes. It keeps track of the loaded subclasses and allows for querying plugins for a given scope or all available ones.

The names of the subclasses are 1:1 mappings of the inspection areas, e.g. the PackagesInspector class would be used for inspection when the user specifies “–scope=packages”.

All subclasses have to implement the

inspect(system, description)

method which inspects the given system and stores the gathered information in the description. It returns a brief summary string of the inspection.

The description object can also be used to store files in the description.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



67
68
69
# File 'lib/inspector.rb', line 67

def description
  @description
end

#systemObject

Returns the value of attribute system.



67
68
69
# File 'lib/inspector.rb', line 67

def system
  @system
end

Class Method Details

.allObject



51
52
53
# File 'lib/inspector.rb', line 51

def all
  @inspectors
end

.all_scopesObject



55
56
57
# File 'lib/inspector.rb', line 55

def all_scopes
  all.map(&:scope)
end

.for(scope) ⇒ Object



45
46
47
48
49
# File 'lib/inspector.rb', line 45

def for(scope)
  class_name = "#{scope.split("_").map(&:capitalize).join}Inspector"

  Object.const_get(class_name) if Object.const_defined?(class_name)
end

.inherited(klass) ⇒ Object



41
42
43
# File 'lib/inspector.rb', line 41

def inherited(klass)
  @inspectors << klass
end

.scopeObject



59
60
61
62
63
64
# File 'lib/inspector.rb', line 59

def scope
  # Return the un-camelcased name of the inspector,
  # e.g. "foo_bar" for "FooBarInspector"
  scope = self.name.match(/^(.*)Inspector$/)[1]
  scope.gsub(/([^A-Z])([A-Z])/, "\\1_\\2").downcase
end

Instance Method Details

#scopeObject



69
70
71
# File 'lib/inspector.rb', line 69

def scope
  self.class.scope
end