Sha256: 7a93c6e3e5cd40b87946a79b1f5bfb3a0471d4df9ee0d3b47535298f33c7a0a2

Contents?: true

Size: 851 Bytes

Versions: 2

Compression:

Stored size: 851 Bytes

Contents

# This is the base class for the registrars.
#  It defines the interface that other registrars inherit.
#  This is an abstract class.
#  The child classes inheriting this interface must define the 'value' method.
module DispatchRider
  module Registrars
    class Base
      attr_reader :store

      def initialize
        @store = {}
      end

      def register(name, options = {})
        store[name.to_sym] = value(name, options)
        self
      rescue NameError
        raise NotFound, name
      end

      def value(name, options = {})
        raise NotImplementedError
      end

      def unregister(name)
        store.delete(name.to_sym)
        self
      end

      def fetch(name)
        begin
          store.fetch(name.to_sym)
        rescue IndexError
          raise NotRegistered, name
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dispatch-rider-2.1.0 lib/dispatch-rider/registrars/base.rb
dispatch-rider-2.0.0 lib/dispatch-rider/registrars/base.rb