Class: ForemanMaintain::Detector

Inherits:
Object
  • Object
show all
Includes:
Concerns::Logger
Defined in:
lib/foreman_maintain/detector.rb

Instance Method Summary collapse

Methods included from Concerns::Logger

#logger

Constructor Details

#initializeDetector

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



79
80
81
# File 'lib/foreman_maintain/detector.rb', line 79

def all_scenarios(filter_conditions = nil)
  filter(@scenarios.map(&:new), filter_conditions)
end

#available_checks(filter_conditions = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/foreman_maintain/detector.rb', line 36

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



31
32
33
34
# File 'lib/foreman_maintain/detector.rb', line 31

def available_features(filter_conditions = nil)
  ensure_features_detected
  filter(@available_features, filter_conditions)
end

#available_procedures(filter_conditions = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/foreman_maintain/detector.rb', line 44

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



59
60
61
62
63
64
65
66
67
# File 'lib/foreman_maintain/detector.rb', line 59

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_detectedObject



69
70
71
72
73
74
75
76
77
# File 'lib/foreman_maintain/detector.rb', line 69

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



52
53
54
55
56
57
# File 'lib/foreman_maintain/detector.rb', line 52

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

#refreshObject



21
22
23
24
25
26
27
28
29
# 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
  @available_procedures = nil
  @scenarios ||= Scenario.all_sub_classes.select(&:autodetect?)
end