Class: Rodbot::Services

Inherits:
Object
  • Object
show all
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

Classes: App, Relay, Schedule

Instance Method Summary collapse

Constructor Details

#initializeServices

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

Returns:

  • (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