Sha256: 4f11b91a4f479af7b413c9e33eba3ea23dd45cecd7d2580dc72993fbb8cba2f6

Contents?: true

Size: 823 Bytes

Versions: 2

Compression:

Stored size: 823 Bytes

Contents

# frozen_string_literal: true

module Waylon
  # Registry of Sense subclasses known to Waylon
  class SenseRegistry
    include Singleton

    # A convenience wrapper around the singleton instance #register method
    # @param (see #register)
    # @return (see #register)
    def self.register(name, class_name)
      instance.register(name, class_name)
    end

    # Add the provided Sense class to the registry under `name`
    # @param name [String] The name of the Sense in the registry
    # @param class_name [Class] The Sense subclass to add
    # @return [Class] The Sense subclass
    def register(name, class_name)
      @senses ||= {}
      @senses[name.to_s] = class_name
    end

    # Provides a Hash version of this registry
    # @return [Hash]
    def to_hash
      (@senses || {}).dup
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
waylon-core-0.1.1 lib/waylon/sense_registry.rb
waylon-core-0.1.0 lib/waylon/sense_registry.rb