Module: Amp::Help::HelpRegistry
Overview
Module handling the registration and retrieval of entries in the help system.
This is a singleton module. Don’t mix it in anywhere. That’d be silly.
Instance Method Summary collapse
-
#[](entry) ⇒ Array<HelpEntry>
Returns a list of HelpEntrys with the given name.
-
#entries ⇒ Hash{String => Array<HelpEntry>}
Retrives the entries hash which stores all the help entrys.
-
#register(name, entry) ⇒ Object
Adds an entry to the registry.
-
#unregister(name, entry = nil) ⇒ Object
Unregisters the given entry from the registry.
Instance Method Details
#[](entry) ⇒ Array<HelpEntry>
Returns a list of HelpEntrys with the given name. Since we allow for the possibility of overlap by name, this returns an array.
42 43 44 |
# File 'lib/amp-front/help/help.rb', line 42 def [](entry) entries[entry] end |
#entries ⇒ Hash{String => Array<HelpEntry>}
Retrives the entries hash which stores all the help entrys
32 33 34 |
# File 'lib/amp-front/help/help.rb', line 32 def entries @entries ||= Hash.new() {|h,k| h[k] = []} end |
#register(name, entry) ⇒ Object
Adds an entry to the registry. We take a name and an entry, and store the entry under the list of entries with the given name.
53 54 55 |
# File 'lib/amp-front/help/help.rb', line 53 def register(name, entry) entries[name] << entry end |
#unregister(name, entry = nil) ⇒ Object
Unregisters the given entry from the registry. Not sure why you might use this, but it’s a capability.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/amp-front/help/help.rb', line 64 def unregister(name, entry=nil) case entries[name].size when 0 raise ArgumentError.new("No help entry named '#{name}' found.") when 1 entries[name].clear else if entry.nil? raise ArgumentError.new("Multiple help entries named '#{name}': " + 'you must provide which one to remove to ' + '#unregister.') else entries[name].delete entry end end end |