Sha256: 6c269918525898df0cc39fe6c4306003c16bfdc1effaba5a0ff47c4a6dd3e2d2

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

module Backport
  module Server
    # An extendable server class that provides basic start/stop functionality
    # and common callbacks.
    #
    class Base
      # Start the server.
      #
      def start
        return if started?
        starting
        @started = true
      end

      # Stop the server.
      #
      def stop
        return if stopped?
        stopping
        @started = false
      end

      def started?
        @started ||= false
      end

      def stopped?
        !started?
      end

      # A callback triggered when a Machine starts running or the server is
      # added to a running machine. Subclasses should override this method to
      # provide their own functionality.
      #
      # @return [void]
      def starting; end

      # A callback triggered when the server is stopping. Subclasses should
      # override this method to provide their own functionality.
      #
      # @return [void]
      def stopping; end

      # A callback triggered from the main loop of a running Machine.
      # Subclasses should override this method to provide their own
      # functionality.
      #
      # @return [void]
      def tick; end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
backport-1.0.0 lib/backport/server/base.rb
backport-0.3.0 lib/backport/server/base.rb