Module: RSMP::Components

Included in:
Site, SiteProxy
Defined in:
lib/rsmp/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/components.rb', line 5

def components
  @components
end

#mainObject (readonly)

Returns the value of attribute main.



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

def main
  @main
end

Instance Method Details

#add_component(component) ⇒ Object



38
39
40
# File 'lib/rsmp/components.rb', line 38

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

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



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

def aggregated_status_changed component, options={}
end

#check_main_component(settings) ⇒ Object



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

def check_main_component settings
  unless settings['main'] && settings['main'].size >= 1
    raise ConfigurationError.new("main component must be defined")
  end
  if settings['main'].size > 1
    raise ConfigurationError.new("only one main component can be defined, found #{settings['main'].keys.join(', ')}")
  end
end

#clear_alarm_timestampsObject



61
62
63
# File 'lib/rsmp/components.rb', line 61

def clear_alarm_timestamps
  @components.values.each {|component| component.clear_alarm_timestamps }
end

#find_component(component_id, build: true) ⇒ Object



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

def find_component component_id, build: true
  component = @components[component_id]
  return component if component
  if 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 (class_name == 'Component' || class_name == 'ComponentProxy')
    log "Added component #{component_id} with the inferred type #{class_name}", level: :debug
    component
  else
  end
end

#infer_component_type(component_id) ⇒ Object

Raises:



42
43
44
# File 'lib/rsmp/components.rb', line 42

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

#initialize_componentsObject



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

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

#setup_components(settings) ⇒ Object



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

def setup_components settings
  return unless settings
  check_main_component settings
  settings.each_pair do |type,components_by_type|
    if 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
end