Class: ForemanMaintain::Detector
- Inherits:
-
Object
- Object
- ForemanMaintain::Detector
- Includes:
- Concerns::Logger
- Defined in:
- lib/foreman_maintain/detector.rb
Instance Method Summary collapse
- #all_scenarios(filter_conditions = nil) ⇒ Object
- #available_checks(filter_conditions = nil) ⇒ Object
- #available_features(filter_conditions = nil) ⇒ Object
- #available_procedures(filter_conditions = nil) ⇒ Object
- #available_scenarios(filter_conditions = nil) ⇒ Object
- #ensure_features_detected ⇒ Object
-
#feature(label) ⇒ Object
Returns instance of feature detected on system by label.
- #filter(collection, conditions) ⇒ Object
- #find_present_classes(object_base_class) ⇒ Object
-
#initialize ⇒ Detector
constructor
A new instance of Detector.
- #refresh ⇒ Object
Methods included from Concerns::Logger
Constructor Details
#initialize ⇒ Detector
Returns a new instance of Detector.
5 6 7 |
# File 'lib/foreman_maintain/detector.rb', line 5 def initialize refresh end |
Instance Method Details
#all_scenarios(filter_conditions = nil) ⇒ Object
78 79 80 |
# File 'lib/foreman_maintain/detector.rb', line 78 def all_scenarios(filter_conditions = nil) filter(@scenarios.map(&:new), filter_conditions) end |
#available_checks(filter_conditions = nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/foreman_maintain/detector.rb', line 35 def available_checks(filter_conditions = nil) unless @available_checks ensure_features_detected @available_checks = find_present_classes(Check) end filter(@available_checks, filter_conditions) end |
#available_features(filter_conditions = nil) ⇒ Object
30 31 32 33 |
# File 'lib/foreman_maintain/detector.rb', line 30 def available_features(filter_conditions = nil) ensure_features_detected filter(@available_features, filter_conditions) end |
#available_procedures(filter_conditions = nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/foreman_maintain/detector.rb', line 43 def available_procedures(filter_conditions = nil) unless @available_procedures ensure_features_detected @available_procedures = find_present_classes(Procedure) end filter(@available_procedures, filter_conditions) end |
#available_scenarios(filter_conditions = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/foreman_maintain/detector.rb', line 58 def available_scenarios(filter_conditions = nil) unless @available_scenarios ensure_features_detected @available_scenarios = @scenarios.select do |scenario| scenario.present? && scenario.autodetect? end.map(&:new) end filter(@available_scenarios, filter_conditions) end |
#ensure_features_detected ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/foreman_maintain/detector.rb', line 68 def ensure_features_detected return if @all_features_scanned @available_features = [] @features_by_label = {} autodetect_features.each_key do |label| detect_feature(label) end @all_features_scanned = true end |
#feature(label) ⇒ Object
Returns instance of feature detected on system by label
10 11 12 |
# File 'lib/foreman_maintain/detector.rb', line 10 def feature(label) detect_feature(label) end |
#filter(collection, conditions) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/foreman_maintain/detector.rb', line 14 def filter(collection, conditions) if conditions collection = collection.find_all { |object| match_object?(object, conditions) } end sort(collection) end |
#find_present_classes(object_base_class) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/foreman_maintain/detector.rb', line 51 def find_present_classes(object_base_class) object_base_class.all_sub_classes.reduce([]) do |array, object_class| array << object_class if object_class.autodetect? && object_class.present? array end end |
#refresh ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/foreman_maintain/detector.rb', line 21 def refresh @features_by_label = {} @available_features = [] @all_features_scanned = false @available_checks = nil @available_scenarios = nil @scenarios ||= Scenario.all_sub_classes.select(&:autodetect?) end |