Class: Waylon::SenseRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/waylon/sense_registry.rb

Overview

Registry of Sense subclasses known to Waylon

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sensesObject (readonly)

Returns the value of attribute senses.



8
9
10
# File 'lib/waylon/sense_registry.rb', line 8

def senses
  @senses
end

Class Method Details

.register(name, class_name) ⇒ Class

A convenience wrapper around the singleton instance #register method

Parameters:

  • name (String)

    The name of the Sense in the registry

  • class_name (Class)

    The Sense subclass to add

Returns:

  • (Class)

    The Sense subclass



13
14
15
# File 'lib/waylon/sense_registry.rb', line 13

def self.register(name, class_name)
  instance.register(name, class_name)
end

Instance Method Details

#register(name, class_name) ⇒ Class

Add the provided Sense class to the registry under ‘name`

Parameters:

  • name (String)

    The name of the Sense in the registry

  • class_name (Class)

    The Sense subclass to add

Returns:

  • (Class)

    The Sense subclass



21
22
23
24
# File 'lib/waylon/sense_registry.rb', line 21

def register(name, class_name)
  @senses ||= {}
  @senses[name.to_s] = class_name
end

#to_hashHash

Provides a Hash version of this registry

Returns:

  • (Hash)


28
29
30
# File 'lib/waylon/sense_registry.rb', line 28

def to_hash
  (@senses || {}).dup
end