Class: Needle::Pipeline::Element

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/needle/pipeline/element.rb

Overview

The base class of instantiation pipeline elements. All subclasses MUST implement is the #call method, to define the logic that instances of that pipeline element should perform when invoked.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(point, name = nil, priority = nil, options = {}) ⇒ Element

Create a new element instance with the given name and priority. This will call #initialize_element, so that subclasses only need to implement that method if they have any initialization logic to perform.


59
60
61
62
63
64
# File 'lib/needle/pipeline/element.rb', line 59

def initialize( point, name=nil, priority=nil, options={} )
  @service_point = point
  @name, @priority = name, ( priority || self.class.default_priority )
  @options = options
  initialize_element
end

Class Attribute Details

.default_priorityObject (readonly)

The default priority to use for elements of this type.


45
46
47
# File 'lib/needle/pipeline/element.rb', line 45

def default_priority
  @default_priority
end

Instance Attribute Details

#nameObject (readonly)

The name of this element (may be nil).


30
31
32
# File 'lib/needle/pipeline/element.rb', line 30

def name
  @name
end

#optionsObject (readonly)

The hash of options that were given to this element.


37
38
39
# File 'lib/needle/pipeline/element.rb', line 37

def options
  @options
end

#priorityObject (readonly)

The priority of this element, used to determine ordering. Higher ordered elements are invoked before lower-ordered elements.


34
35
36
# File 'lib/needle/pipeline/element.rb', line 34

def priority
  @priority
end

#service_pointObject (readonly)

The service definition that this element belongs to.


27
28
29
# File 'lib/needle/pipeline/element.rb', line 27

def service_point
  @service_point
end

#succObject

The next element in the chain. This value is only valid during pipeline execution–its value should not be relied upon at any other time.


41
42
43
# File 'lib/needle/pipeline/element.rb', line 41

def succ
  @succ
end

Class Method Details

.set_default_priority(priority) ⇒ Object

Set the default priority for elements of this type. Subclasses may use this method to set their default priority.


49
50
51
# File 'lib/needle/pipeline/element.rb', line 49

def set_default_priority( priority )
  @default_priority = priority
end

Instance Method Details

#<=>(element) ⇒ Object

Orders elements by their priority.


72
73
74
# File 'lib/needle/pipeline/element.rb', line 72

def <=>( element )
  priority <=> element.priority
end

#call(*args) ⇒ Object Also known as: []

Invoke this element's logic.

Raises:

  • (NotImplementedError)

77
78
79
# File 'lib/needle/pipeline/element.rb', line 77

def call( *args )
  raise NotImplementedError
end

#initialize_elementObject

Invoked by the constructor to perform any subclass-specific initialization logic.


68
69
# File 'lib/needle/pipeline/element.rb', line 68

def initialize_element
end