Class Mack::Utils::RegistryMap
In: lib/mack-facets/utils/registry_map.rb
Parent: Object

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

Methods

Included Modules

Singleton Extlib::Hook

Attributes

registered_items  [R]  The list of registered items

Public Class methods

Adds an object to the list at a specified position. By default the position is last.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 70
70:         def add(tag, klass, position = -1)
71:           self.instance.add(tag, klass, position)
72:         end

Emptys out the list of registered_items.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 60
60:         def clear!
61:           registered_items.clear
62:         end

Moves an object to the bottom of the registered_items list.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 85
85:         def move_to_bottom(tag, klass)
86:           remove(tag, klass)
87:           self.instance.add(tag, klass)
88:         end

Moves an object to the top of the registered_items list.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 80
80:         def move_to_top(tag, klass)
81:           self.instance.add(tag, klass, 0)
82:         end

Returns the list of registered items.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 55
55:         def registered_items
56:           self.instance.registered_items
57:         end

Removes an object from the list.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 75
75:         def remove(tag, klass)
76:           self.instance.remove(tag, klass)
77:         end

Resets the registered_items list to the list specified by the initial_state method.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 65
65:         def reset!
66:           self.instance.reset!
67:         end

Public Instance methods

Adds an object to the list at a specified position. By default the position is last.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 36
36:       def add(tag, klass, position = -1)
37:         @registered_items[tag] ||= []
38:         arr = self.registered_items[tag]
39:         position = arr.size if position == -1
40:         
41:         arr.insert(position, klass)
42:         arr.uniq!
43:         arr.compact!
44:       end

Override this method to set the initial state of the registered_items Array. By default this list is empty.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 26
26:       def initial_state
27:         {}
28:       end

Removes an object from the list.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 47
47:       def remove(tag, klass)
48:         return false if @registered_items[tag] == nil
49:         self.registered_items[tag].delete(klass)
50:       end

Resets the registered_items list to the list specified by the initial_state method.

[Source]

    # File lib/mack-facets/utils/registry_map.rb, line 31
31:       def reset!
32:         @registered_items = self.initial_state.dup
33:       end

[Validate]