Module: RSMP::Components

Included in:
Site, SiteProxy
Defined in:
lib/rsmp/component/components.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



5
6
7
# File 'lib/rsmp/component/components.rb', line 5

def components
  @components
end

#mainObject (readonly)

Returns the value of attribute main.



5
6
7
# File 'lib/rsmp/component/components.rb', line 5

def main
  @main
end

Instance Method Details

#add_component(component) ⇒ Object



36
37
38
# File 'lib/rsmp/component/components.rb', line 36

def add_component(component)
  @components[component.c_id] = component
end

#aggregated_status_changed(component, options = {}) ⇒ Object



12
# File 'lib/rsmp/component/components.rb', line 12

def aggregated_status_changed(component, options = {}); end

#check_main_component(settings) ⇒ Object

Raises:



29
30
31
32
33
34
# File 'lib/rsmp/component/components.rb', line 29

def check_main_component(settings)
  raise ConfigurationError, 'main component must be defined' unless settings['main'] && settings['main'].size >= 1
  return unless settings['main'].size > 1

  raise ConfigurationError, "only one main component can be defined, found #{settings['main'].keys.join(', ')}"
end

#clear_alarm_timestampsObject



59
60
61
# File 'lib/rsmp/component/components.rb', line 59

def clear_alarm_timestamps
  @components.each_value(&:clear_alarm_timestamps)
end

#find_component(component_id, build: true) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rsmp/component/components.rb', line 44

def find_component(component_id, build: true)
  component = @components[component_id]
  return component if component

  return unless build

  inferred_type = infer_component_type component_id
  component = inferred_type.new node: self, id: component_id
  @components[component_id] = component
  class_name = component.class.name.split('::').last
  class_name << ' component' unless %w[Component ComponentProxy].include?(class_name)
  log "Added component #{component_id} with the inferred type #{class_name}", level: :debug
  component
end

#infer_component_type(component_id) ⇒ Object

Raises:



40
41
42
# File 'lib/rsmp/component/components.rb', line 40

def infer_component_type(component_id)
  raise UnknownComponent, "Component #{component_id} mising and cannot infer type"
end

#initialize_componentsObject



7
8
9
10
# File 'lib/rsmp/component/components.rb', line 7

def initialize_components
  @components = {}
  @main = nil
end

#setup_components(settings) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rsmp/component/components.rb', line 14

def setup_components(settings)
  return unless settings

  check_main_component settings
  settings.each_pair do |type, components_by_type|
    next unless components_by_type

    components_by_type.each_pair do |id, component_settings|
      component_settings ||= {}
      @components[id] = build_component(id: id, type: type, settings: component_settings)
      @main = @components[id] if type == 'main'
    end
  end
end