Class: MIDB::API::Hooks
- Inherits:
-
Object
- Object
- MIDB::API::Hooks
- Defined in:
- lib/midb/hooks.rb
Instance Attribute Summary collapse
-
#hooks ⇒ Object
Returns the value of attribute hooks.
Instance Method Summary collapse
- #after_get_all_entries(n_entries) ⇒ Object
- #format_field(field, what) ⇒ Object
-
#initialize ⇒ Hooks
constructor
A new instance of Hooks.
-
#register(hook, method) ⇒ Object
This method adds a method reference (:whatever) to the hash defined above.
Constructor Details
#initialize ⇒ Hooks
12 13 14 15 16 |
# File 'lib/midb/hooks.rb', line 12 def initialize() @hooks = Hash.new @hooks["after_get_all_entries"] = [] @hooks["format_field"] = [] end |
Instance Attribute Details
#hooks ⇒ Object
Returns the value of attribute hooks.
11 12 13 |
# File 'lib/midb/hooks.rb', line 11 def hooks @hooks end |
Instance Method Details
#after_get_all_entries(n_entries) ⇒ Object
28 29 30 31 32 33 |
# 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) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# 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) ⇒ Object
This method adds a method reference (:whatever) to the hash defined above.
19 20 21 |
# File 'lib/midb/hooks.rb', line 19 def register(hook, method) @hooks[hook].push method end |