Class: Rodbot::Services
- Inherits:
-
Object
- Object
- Rodbot::Services
- Extended by:
- Forwardable
- Defined in:
- lib/rodbot/services.rb,
lib/rodbot/services/app.rb,
lib/rodbot/services/relay.rb,
lib/rodbot/services/schedule.rb
Overview
Foundation to run app, relay and schedule services
Defined Under Namespace
Instance Method Summary collapse
- #exist?(service) ⇒ Boolean
-
#initialize ⇒ Services
constructor
A new instance of Services.
- #register(service, extension: nil) ⇒ Object
Constructor Details
#initialize ⇒ Services
Returns a new instance of Services.
14 15 16 |
# File 'lib/rodbot/services.rb', line 14 def initialize @dispatcher = Rodbot::Dispatcher.new('rodbot') end |
Instance Method Details
#exist?(service) ⇒ Boolean
18 19 20 |
# File 'lib/rodbot/services.rb', line 18 def exist?(service) Rodbot::SERVICES.include? service.to_sym end |
#register(service, extension: nil) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/rodbot/services.rb', line 22 def register(service, extension: nil) fail(Rodbot::ServiceError, "unknown service #{service}") unless exist? service tasks = "rodbot/services/#{service}".constantize.new.tasks(only: extension) tasks.each_with_index do |task, index| name = [service, (index if tasks.count > 1)].compact.join('-') @dispatcher.register(name, &task) end end |