Module: RSMP::Components
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
Instance Method Summary collapse
- #add_component(component) ⇒ Object
- #aggregated_status_changed(component, options = {}) ⇒ Object
- #check_main_component(settings) ⇒ Object
- #find_component(component_id, build: true) ⇒ Object
- #infer_component_type(component_id) ⇒ Object
- #initialize_components ⇒ Object
- #setup_components(settings) ⇒ Object
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
5 6 7 |
# File 'lib/rsmp/components.rb', line 5 def components @components end |
#main ⇒ Object (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, ={} 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 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
41 42 43 |
# File 'lib/rsmp/components.rb', line 41 def infer_component_type component_id Component end |
#initialize_components ⇒ Object
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,settings| @components[id] = build_component(id:id, type:type, settings:settings) @main = @components[id] if type=='main' end end end end |