Class: RBoss::ComponentProcessor
- Inherits:
-
Object
- Object
- RBoss::ComponentProcessor
- Defined in:
- lib/rboss/component_processor.rb
Direct Known Subclasses
Instance Method Summary collapse
- #add(component_id, config = {}) ⇒ Object
- #defaults(component_id, defaults) ⇒ Object
-
#initialize(&block) ⇒ ComponentProcessor
constructor
A new instance of ComponentProcessor.
- #process_components ⇒ Object
-
#register(component_id, params) ⇒ Object
Register a component using the given id (which must be used for adding it to process) and parameters.
Constructor Details
#initialize(&block) ⇒ ComponentProcessor
Returns a new instance of ComponentProcessor.
73 74 75 76 |
# File 'lib/rboss/component_processor.rb', line 73 def initialize &block @process = block @process ||= lambda { |type, config| type.new(config).process } end |
Instance Method Details
#add(component_id, config = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rboss/component_processor.rb', line 92 def add component_id, config = {} registered_component = @components[component_id] return unless registered_component defaults = registered_component[:defaults] registered_component[:enabled] = true config = defaults.merge config if config.is_a? Hash if registered_component[:multiple_instances] registered_component[:configs] << config else registered_component[:config] = config end propagate_configs registered_component end |
#defaults(component_id, defaults) ⇒ Object
106 107 108 109 |
# File 'lib/rboss/component_processor.rb', line 106 def defaults component_id, defaults registered_component = @components[component_id] registered_component[:defaults] = defaults if registered_component end |
#process_components ⇒ Object
111 112 113 114 115 116 |
# File 'lib/rboss/component_processor.rb', line 111 def process_components enabled_components = @components.find_all { |component_id, params| params[:enabled] } (enabled_components.sort_by { |key, value| value[:priority] }).each do |key, component| process_component component end end |
#register(component_id, params) ⇒ Object
Register a component using the given id (which must be used for adding it to process) and parameters
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rboss/component_processor.rb', line 79 def register component_id, params params = { :type => nil, :multiple_instances => false, :priority => 0, :enabled => false, :defaults => {} }.merge! params @components ||= {} params[:configs] ||= [] if params[:multiple_instances] @components[component_id] = params unless @components.has_key? component_id end |