Class: Machinery::Inspector

Inherits:
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.



91
92
93
# File 'lib/inspector.rb', line 91

def description
  @description
end

#systemObject

Returns the value of attribute system.



91
92
93
# File 'lib/inspector.rb', line 91

def system
  @system
end

Class Method Details

.allObject



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

def all
  @inspectors
end

.all_scopesObject



63
64
65
# File 'lib/inspector.rb', line 63

def all_scopes
  sort_scopes(all.map(&:scope))
end

.for(scope) ⇒ Object



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

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

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

.has_priority(value) ⇒ Object



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

def has_priority(value)
  @priority = value
end

.inherited(klass) ⇒ Object



49
50
51
# File 'lib/inspector.rb', line 49

def inherited(klass)
  @inspectors << klass
end

.priorityObject



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

def priority
  @priority || 1000
end

.scopeObject



83
84
85
86
87
88
# File 'lib/inspector.rb', line 83

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

.sort_scopes(scope_list) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/inspector.rb', line 67

def sort_scopes(scope_list)
  scope_priority = {}

  visible_scopes = Machinery::Scope.visible_scopes.map(&:scope_name)
  scope_list.each do |scope|
    inspector = self.for(scope)
    next if !inspector || !visible_scopes.include?(scope)

    scope_priority[inspector.priority] = scope
  end

  scope_priority.sort.map do |key, value|
    scope_priority[key] = value
  end
end

Instance Method Details

#scopeObject



93
94
95
# File 'lib/inspector.rb', line 93

def scope
  self.class.scope
end