Class: BlabberMouth::Utils::RegistryList
- Inherits:
-
Object
- Object
- BlabberMouth::Utils::RegistryList
- Includes:
- Singleton
- Defined in:
- lib/blabber_mouth/utils/registry_list.rb
Overview
This is a general purpose Singleton Registry class. It takes the drudgery out of creating registry classes, that are, let’s face it, all pretty much the same.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#registered_items ⇒ Object
readonly
The list of registered items.
Class Method Summary collapse
-
.add(klass, position = registered_items.size) ⇒ Object
Adds an object to the list at a specified position.
-
.clear! ⇒ Object
Emptys out the list of registered_items.
-
.move_to_bottom(klass) ⇒ Object
Moves an object to the bottom of the registered_items list.
-
.move_to_top(klass) ⇒ Object
Moves an object to the top of the registered_items list.
-
.registered_items ⇒ Object
Returns the list of registered items.
-
.remove(klass) ⇒ Object
Removes an object from the list.
-
.reset! ⇒ Object
Resets the registered_items list to the list specified by the initial_state method.
Instance Method Summary collapse
-
#add(klass, position = self.registered_items.size) ⇒ Object
Adds an object to the list at a specified position.
-
#initial_state ⇒ Object
Override this method to set the initial state of the registered_items Array.
-
#initialize ⇒ RegistryList
constructor
:nodoc:.
-
#remove(klass) ⇒ Object
Removes an object from the list.
-
#reset! ⇒ Object
Resets the registered_items list to the list specified by the initial_state method.
Constructor Details
#initialize ⇒ RegistryList
:nodoc:
13 14 15 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 13 def initialize # :nodoc: reset! end |
Instance Attribute Details
#registered_items ⇒ Object (readonly)
The list of registered items
11 12 13 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 11 def registered_items @registered_items end |
Class Method Details
.add(klass, position = registered_items.size) ⇒ Object
Adds an object to the list at a specified position. By default the position is last.
58 59 60 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 58 def add(klass, position = registered_items.size) self.instance.add(klass, position) end |
.clear! ⇒ Object
Emptys out the list of registered_items.
48 49 50 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 48 def clear! registered_items.clear end |
.move_to_bottom(klass) ⇒ Object
Moves an object to the bottom of the registered_items list.
73 74 75 76 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 73 def move_to_bottom(klass) remove(klass) self.instance.add(klass) end |
.move_to_top(klass) ⇒ Object
Moves an object to the top of the registered_items list.
68 69 70 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 68 def move_to_top(klass) self.instance.add(klass, 0) end |
.registered_items ⇒ Object
Returns the list of registered items.
43 44 45 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 43 def registered_items self.instance.registered_items end |
.remove(klass) ⇒ Object
Removes an object from the list.
63 64 65 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 63 def remove(klass) self.instance.remove(klass) end |
.reset! ⇒ Object
Resets the registered_items list to the list specified by the initial_state method.
53 54 55 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 53 def reset! self.instance.reset! end |
Instance Method Details
#add(klass, position = self.registered_items.size) ⇒ Object
Adds an object to the list at a specified position. By default the position is last.
29 30 31 32 33 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 29 def add(klass, position = self.registered_items.size) self.registered_items.insert(position, klass) self.registered_items.uniq! self.registered_items.compact! end |
#initial_state ⇒ Object
Override this method to set the initial state of the registered_items Array. By default this list is empty.
19 20 21 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 19 def initial_state [] end |
#remove(klass) ⇒ Object
Removes an object from the list.
36 37 38 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 36 def remove(klass) self.registered_items.delete(klass) end |
#reset! ⇒ Object
Resets the registered_items list to the list specified by the initial_state method.
24 25 26 |
# File 'lib/blabber_mouth/utils/registry_list.rb', line 24 def reset! @registered_items = self.initial_state.dup end |