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

Instance Method Details

#add_component(component) ⇒ Object



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

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

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



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

def aggregated_status_changed component, options={}
end

#build_component(id:, type:, settings: {}) ⇒ Object



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

def build_component id:, type:, settings:{}
  Component.new id:id, node: self, grouped: type=='main'
end

#check_main_component(settings) ⇒ Object



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

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



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

def find_component component_id, build: true
  component = @components[component_id]
  return component if component
  if build
    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 << " compoent" unless class_name == 'Component'
    log "Inferred #{class_name} #{component_id}", level: :debug
    component
  else
    raise UnknownComponent.new("Component #{component_id} not found") unless component
  end
end

#infer_component_type(component_id) ⇒ Object



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

def infer_component_type component_id
  Component
end

#initialize_componentsObject



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

def initialize_components
  @components = {}
end

#setup_components(settings) ⇒ Object



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

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,settings|
        @components[id] = build_component(id:id, type:type, settings:settings)
      end
    end
  end
end