Class: Needle::Pipeline::Element
- Inherits:
-
Object
- Object
- Needle::Pipeline::Element
- 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.
Direct Known Subclasses
Lifecycle::Deferred, Lifecycle::Initialize, Lifecycle::Multiton, Lifecycle::Singleton, Lifecycle::Threaded, Collection::BlockElement, InterceptorElement
Class Attribute Summary collapse
-
.default_priority ⇒ Object
readonly
The default priority to use for elements of this type.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of this element (may be
nil
). -
#options ⇒ Object
readonly
The hash of options that were given to this element.
-
#priority ⇒ Object
readonly
The priority of this element, used to determine ordering.
-
#service_point ⇒ Object
readonly
The service definition that this element belongs to.
-
#succ ⇒ Object
The next element in the chain.
Class Method Summary collapse
-
.set_default_priority(priority) ⇒ Object
Set the default priority for elements of this type.
Instance Method Summary collapse
-
#<=>(element) ⇒ Object
Orders elements by their priority.
-
#call(*args) ⇒ Object
(also: #[])
Invoke this element’s logic.
-
#initialize(point, name = nil, priority = nil, options = {}) ⇒ Element
constructor
Create a new element instance with the given name and priority.
-
#initialize_element ⇒ Object
Invoked by the constructor to perform any subclass-specific initialization logic.
-
#reset! ⇒ Object
Invoked by Pipeline::Collection#reset!.
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, ={} ) @service_point = point @name, @priority = name, ( priority || self.class.default_priority ) @options = initialize_element end |
Class Attribute Details
.default_priority ⇒ Object (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
#name ⇒ Object (readonly)
The name of this element (may be nil
).
30 31 32 |
# File 'lib/needle/pipeline/element.rb', line 30 def name @name end |
#options ⇒ Object (readonly)
The hash of options that were given to this element.
37 38 39 |
# File 'lib/needle/pipeline/element.rb', line 37 def @options end |
#priority ⇒ Object (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_point ⇒ Object (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 |
#succ ⇒ Object
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.
77 78 79 |
# File 'lib/needle/pipeline/element.rb', line 77 def call( *args ) raise NotImplementedError end |
#initialize_element ⇒ Object
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 |
#reset! ⇒ Object
Invoked by Pipeline::Collection#reset!. Subclasses of Element that save any kind of state should override this method to clear that state on demand.
84 85 |
# File 'lib/needle/pipeline/element.rb', line 84 def reset! end |