class MIDB::API::Hooks

Attributes

hooks[RW]

Public Class Methods

new() click to toggle source
# File lib/midb/hooks.rb, line 12
def initialize()
  @hooks = Hash.new
  @hooks["after_get_all_entries"] = []
  @hooks["format_field"] = []
end

Public Instance Methods

after_get_all_entries(n_entries) click to toggle source

These are the methods that are ran when the hook is called from the main class. The code can be slightly modified depending on the arguments that each hook takes, but that's up to the original developer - not the one who does the customization.

# File lib/midb/hooks.rb, line 28
def after_get_all_entries(n_entries)
  @hooks["after_get_all_entries"].each do |f|
    # Just run :f whenever this method is called, no arguments.
    Object.send(f, n_entries)
  end
end
format_field(field, what) click to toggle source
# File lib/midb/hooks.rb, line 35
def format_field(field, what)
  if @hooks["format_field"] == []
    return what
  else
    @hooks["format_field"].each do |f|
      return Object.send(f, field, what)
    end
  end
end
register(hook, method) click to toggle source

This method adds a method reference (:whatever) to the hash defined above.

# File lib/midb/hooks.rb, line 19
def register(hook, method)
  @hooks[hook].push method
end