Class: Machinery::Inspector
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
-
#description ⇒ Object
Returns the value of attribute description.
-
#system ⇒ Object
Returns the value of attribute system.
Class Method Summary collapse
- .all ⇒ Object
- .all_scopes ⇒ Object
- .for(scope) ⇒ Object
- .has_priority(value) ⇒ Object
- .inherited(klass) ⇒ Object
- .priority ⇒ Object
- .scope ⇒ Object
- .sort_scopes(scope_list) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
91 92 93 |
# File 'lib/inspector.rb', line 91 def description @description end |
#system ⇒ Object
Returns the value of attribute system.
91 92 93 |
# File 'lib/inspector.rb', line 91 def system @system end |
Class Method Details
.all ⇒ Object
59 60 61 |
# File 'lib/inspector.rb', line 59 def all @inspectors end |
.all_scopes ⇒ Object
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 |
.priority ⇒ Object
41 42 43 |
# File 'lib/inspector.rb', line 41 def priority @priority || 1000 end |
.scope ⇒ Object
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
#scope ⇒ Object
93 94 95 |
# File 'lib/inspector.rb', line 93 def scope self.class.scope end |