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



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

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



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

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

#find_component(component_id, build: true) ⇒ Object



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

def find_component component_id, build: true
  component = @components[component_id]
  return component if component
  if build && !component_id.empty?
    inferred = infer_component_type component_id
    component = inferred.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 "Adding component #{component_id} with the inferred type #{class_name}", level: :debug
    component
  else
    raise UnknownComponent.new("Component #{component_id} not found") unless component
  end
end

#infer_component_type(component_id) ⇒ Object



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

def infer_component_type component_id
  Component
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
# 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|
        @components[id] = build_component(id:id, type:type, settings:component_settings)
        @main = @components[id] if type=='main'
      end
    end
  end
end