Class: Burr::Plugin

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

Overview

Constant Summary collapse

PRIORITIES =
{
  :lowest  => -100,
  :low     => -10,
  :normal  => 0,
  :high    => 10,
  :highest => 100
}
VALIDS =
[:before_parse, :after_parse, :before_decorate, :after_decorate]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(book) ⇒ Plugin

Initialize a new plugin. This should be overridden by the subclass.

book - The book object.

Returns a new instance.



65
66
67
# File 'lib/burr/plugin.rb', line 65

def initialize(book)
  @book = book
end

Instance Attribute Details

#bookObject

Returns the value of attribute book.



58
59
60
# File 'lib/burr/plugin.rb', line 58

def book
  @book
end

Class Method Details

.<=>(other) ⇒ Object

Spaceship is priority [higher -> lower]

other - The class to be compared.

Returns -1, 0, 1.



52
53
54
# File 'lib/burr/plugin.rb', line 52

def <=>(other)
  PRIORITIES[other.priority] <=> PRIORITIES[self.priority]
end

.inherited(base) ⇒ Object

Install a hook so that subclasses are recorded. This method is only ever called by Ruby itself.



20
21
22
23
# File 'lib/burr/plugin.rb', line 20

def inherited(base)
  subclasses << base
  subclasses.sort!
end

.priority(priority = nil) ⇒ Object

Get or set the priority of this plugin. When called without an argument it returns the priority. When an argument is given, it will set the priority.

Parameters:

  • priority (Symbol) (defaults to: nil)

    The priority (default: nil). Valid options are: :lowest, :low, :normal, :high, :highest

Returns:

  • The Symbol priority.



39
40
41
42
43
44
45
# File 'lib/burr/plugin.rb', line 39

def priority(priority=nil)
  @priority ||= nil
  if priority && PRIORITIES.has_key?(priority)
    @priority = priority
  end
  @priority || :normal
end

.subclassesObject

The list of Classes that have been subclassed.

Returns:

  • An array of Class objects.



28
29
30
# File 'lib/burr/plugin.rb', line 28

def subclasses
  @subclasses ||= []
end