Class: Mack::Utils::RegistryMap
- Includes:
- Extlib::Hook, Singleton
- Defined in:
- lib/mack-facets/utils/registry_map.rb
Overview
Provides a convenient way to register items in a map.
The structure of the registry is { :tag => [content] }, and the items within the array can be arranged anyway the user sees fit.
ds - july 2008
Instance Attribute Summary collapse
-
#registered_items ⇒ Object
readonly
The list of registered items.
Class Method Summary collapse
-
.add(tag, klass, position = -1)) ⇒ Object
Adds an object to the list at a specified position.
-
.clear! ⇒ Object
Emptys out the list of registered_items.
-
.move_to_bottom(tag, klass) ⇒ Object
Moves an object to the bottom of the registered_items list.
-
.move_to_top(tag, klass) ⇒ Object
Moves an object to the top of the registered_items list.
-
.registered_items ⇒ Object
Returns the list of registered items.
-
.remove(tag, 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(tag, klass, position = -1)) ⇒ 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 ⇒ RegistryMap
constructor
:nodoc:.
-
#remove(tag, 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 ⇒ RegistryMap
:nodoc:
20 21 22 |
# File 'lib/mack-facets/utils/registry_map.rb', line 20 def initialize # :nodoc: reset! end |
Instance Attribute Details
#registered_items ⇒ Object (readonly)
The list of registered items
18 19 20 |
# File 'lib/mack-facets/utils/registry_map.rb', line 18 def registered_items @registered_items end |
Class Method Details
.add(tag, klass, position = -1)) ⇒ Object
Adds an object to the list at a specified position. By default the position is last.
70 71 72 |
# File 'lib/mack-facets/utils/registry_map.rb', line 70 def add(tag, klass, position = -1) self.instance.add(tag, klass, position) end |
.clear! ⇒ Object
Emptys out the list of registered_items.
60 61 62 |
# File 'lib/mack-facets/utils/registry_map.rb', line 60 def clear! registered_items.clear end |
.move_to_bottom(tag, klass) ⇒ Object
Moves an object to the bottom of the registered_items list.
85 86 87 88 |
# File 'lib/mack-facets/utils/registry_map.rb', line 85 def move_to_bottom(tag, klass) remove(tag, klass) self.instance.add(tag, klass) end |
.move_to_top(tag, klass) ⇒ Object
Moves an object to the top of the registered_items list.
80 81 82 |
# File 'lib/mack-facets/utils/registry_map.rb', line 80 def move_to_top(tag, klass) self.instance.add(tag, klass, 0) end |
.registered_items ⇒ Object
Returns the list of registered items.
55 56 57 |
# File 'lib/mack-facets/utils/registry_map.rb', line 55 def registered_items self.instance.registered_items end |
.remove(tag, klass) ⇒ Object
Removes an object from the list.
75 76 77 |
# File 'lib/mack-facets/utils/registry_map.rb', line 75 def remove(tag, klass) self.instance.remove(tag, klass) end |
.reset! ⇒ Object
Resets the registered_items list to the list specified by the initial_state method.
65 66 67 |
# File 'lib/mack-facets/utils/registry_map.rb', line 65 def reset! self.instance.reset! end |
Instance Method Details
#add(tag, klass, position = -1)) ⇒ Object
Adds an object to the list at a specified position. By default the position is last.
36 37 38 39 40 41 42 43 44 |
# File 'lib/mack-facets/utils/registry_map.rb', line 36 def add(tag, klass, position = -1) @registered_items[tag] ||= [] arr = self.registered_items[tag] position = arr.size if position == -1 arr.insert(position, klass) arr.uniq! arr.compact! end |
#initial_state ⇒ Object
Override this method to set the initial state of the registered_items Array. By default this list is empty.
26 27 28 |
# File 'lib/mack-facets/utils/registry_map.rb', line 26 def initial_state {} end |
#remove(tag, klass) ⇒ Object
Removes an object from the list.
47 48 49 50 |
# File 'lib/mack-facets/utils/registry_map.rb', line 47 def remove(tag, klass) return false if @registered_items[tag] == nil self.registered_items[tag].delete(klass) end |
#reset! ⇒ Object
Resets the registered_items list to the list specified by the initial_state method.
31 32 33 |
# File 'lib/mack-facets/utils/registry_map.rb', line 31 def reset! @registered_items = self.initial_state.dup end |