Class: Mack::Utils::RegistryList
- Includes:
- Extlib::Hook, Singleton
- Defined in:
- lib/mack-facets/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.
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.
Methods included from Extlib::Hook
Constructor Details
#initialize ⇒ RegistryList
:nodoc:
14 15 16 |
# File 'lib/mack-facets/utils/registry_list.rb', line 14 def initialize # :nodoc: reset! end |
Instance Attribute Details
#registered_items ⇒ Object (readonly)
The list of registered items
12 13 14 |
# File 'lib/mack-facets/utils/registry_list.rb', line 12 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.
59 60 61 |
# File 'lib/mack-facets/utils/registry_list.rb', line 59 def add(klass, position = registered_items.size) self.instance.add(klass, position) end |
.clear! ⇒ Object
Emptys out the list of registered_items.
49 50 51 |
# File 'lib/mack-facets/utils/registry_list.rb', line 49 def clear! registered_items.clear end |
.move_to_bottom(klass) ⇒ Object
Moves an object to the bottom of the registered_items list.
74 75 76 77 |
# File 'lib/mack-facets/utils/registry_list.rb', line 74 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.
69 70 71 |
# File 'lib/mack-facets/utils/registry_list.rb', line 69 def move_to_top(klass) self.instance.add(klass, 0) end |
.registered_items ⇒ Object
Returns the list of registered items.
44 45 46 |
# File 'lib/mack-facets/utils/registry_list.rb', line 44 def registered_items self.instance.registered_items end |
.remove(klass) ⇒ Object
Removes an object from the list.
64 65 66 |
# File 'lib/mack-facets/utils/registry_list.rb', line 64 def remove(klass) self.instance.remove(klass) end |
.reset! ⇒ Object
Resets the registered_items list to the list specified by the initial_state method.
54 55 56 |
# File 'lib/mack-facets/utils/registry_list.rb', line 54 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.
30 31 32 33 34 |
# File 'lib/mack-facets/utils/registry_list.rb', line 30 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.
20 21 22 |
# File 'lib/mack-facets/utils/registry_list.rb', line 20 def initial_state [] end |
#remove(klass) ⇒ Object
Removes an object from the list.
37 38 39 |
# File 'lib/mack-facets/utils/registry_list.rb', line 37 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.
25 26 27 |
# File 'lib/mack-facets/utils/registry_list.rb', line 25 def reset! @registered_items = self.initial_state.dup end |