Sha256: 44c703e66203fdbef5d58ae0a4e92e545fb8dfdf12dd2eae91231a999bf917a1

Contents?: true

Size: 825 Bytes

Versions: 14

Compression:

Stored size: 825 Bytes

Contents

# frozen-string-literal: true

using Rodbot::Refinements

module Rodbot

  # Foundation to run app, relay and schedule services
  class Services
    extend Forwardable

    def_delegator :@dispatcher, :run, :run
    def_delegator :@dispatcher, :interrupt, :interrupt

    def initialize
      @dispatcher = Rodbot::Dispatcher.new('rodbot')
    end

    def exist?(service)
      Rodbot::SERVICES.include? service.to_sym
    end

    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
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rodbot-0.4.5 lib/rodbot/services.rb
rodbot-0.4.4 lib/rodbot/services.rb
rodbot-0.4.3 lib/rodbot/services.rb
rodbot-0.4.2 lib/rodbot/services.rb
rodbot-0.4.1 lib/rodbot/services.rb
rodbot-0.4.0 lib/rodbot/services.rb
rodbot-0.3.4 lib/rodbot/services.rb
rodbot-0.3.3 lib/rodbot/services.rb
rodbot-0.3.2 lib/rodbot/services.rb
rodbot-0.3.1 lib/rodbot/services.rb
rodbot-0.3.0 lib/rodbot/services.rb
rodbot-0.2.0 lib/rodbot/services.rb
rodbot-0.1.1 lib/rodbot/services.rb
rodbot-0.1.0 lib/rodbot/services.rb