Class: Murlsh::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/murlsh/plugin.rb

Overview

Superclass for plugins. How plugins are registered.

Hooks:

  • add_pre - called before a new url is saved run arguments (url, config hash)

  • add_post - called after a new url is saved run arguments (config hash)

  • avatar - called to get an avatar url from an email md5 sum run arguments (avatar url, url, config hash)

  • store_asset - store an asset somewhere where it can be loaded by url run arguments (name, data, config hash)

  • url_display_add - called to display additional information after urls run arguments (markup builder, url, config hash)

  • url_display_pre - called to modify a url on-the-fly before display, does not change database run arguments (url, rack request, config hash)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.hookObject (readonly)

Returns the value of attribute hook.



40
41
42
# File 'lib/murlsh/plugin.rb', line 40

def hook
  @hook
end

.registeredObject (readonly)

Returns the value of attribute registered.



41
42
43
# File 'lib/murlsh/plugin.rb', line 41

def registered
  @registered
end

Class Method Details

.hooks(name) ⇒ Object

Get registered plugins by hook (add_pre, add_post, etc.)



28
29
30
31
32
33
34
35
36
# File 'lib/murlsh/plugin.rb', line 28

def self.hooks(name)
  matches = registered.find_all { |p| p.hook == name }.
    sort { |a,b| a.to_s <=> b.to_s }

  if block_given?
    matches.each { |p| yield p }
  end
  matches
end

.inherited(child) ⇒ Object

Called when a plugin class inherits from this class (the way plugins are registered).



23
24
25
# File 'lib/murlsh/plugin.rb', line 23

def self.inherited(child)
  registered << child
end