Module: Amp::Help::HelpRegistry

Extended by:
HelpRegistry
Included in:
HelpRegistry
Defined in:
lib/amp-front/help/help.rb

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

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.

Parameters:

  • entry (String, #to_s)

    the name of the entry(ies) to retrieve

Returns:



42
43
44
# File 'lib/amp-front/help/help.rb', line 42

def [](entry)
  entries[entry]
end

#entriesHash{String => Array<HelpEntry>}

Retrives the entries hash which stores all the help entrys

Returns:



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.

Parameters:

  • name (String, #to_s)

    the name of the help entry. Allowed to conflict with other entries.

  • entry (HelpEntry)

    the entry to store in the registry



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.

Parameters:

  • name (String, #to_s)

    the name of the entry. Note - you will also need to provide the entry, because there might be naming conflicts.

  • entry (HelpEntry) (defaults to: nil)

    the entry to remove from the registry.



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