Class: Orchestrate::EventType
- Inherits:
-
Object
- Object
- Orchestrate::EventType
- Includes:
- Enumerable
- Defined in:
- lib/orchestrate/event_source.rb
Overview
Manages events of a specific type that belong to a specific KeyValue item.
Defined Under Namespace
Classes: TimeSlice
Instance Attribute Summary collapse
-
#kv_item ⇒ Orchestrate::KeyValue
readonly
The KeyValue this EventType is managing events for.
-
#type ⇒ String
readonly
The name for the type of events this EventType manages.
Instance Method Summary collapse
-
#<<(body) ⇒ Orchestrate::Event
(also: #push)
Creates a new Event of the given type for the associated KeyValue.
-
#<=>(other) ⇒ nil, ...
Equivalent to
String#<=>
. -
#==(other) ⇒ true, false
(also: #eql?)
Equivalent to
String#==
. -
#[](bounds) ⇒ Object
Instantiates a new EventType::List with the given bounds.
-
#after(bound) ⇒ EventType::TimeSlice
Sets the exclusive start boundary for enumeration over events.
-
#before(bound) ⇒ EventType::TimeSlice
Sets the exclusive end boundary for enumeration over events.
-
#each {|event| ... } ⇒ Object
Iterates over events belonging to the KeyValue of the specified Type.
-
#end(bound) ⇒ EventType::TimeSlice
Sets the inclusive end boundary for enumeration over events.
-
#initialize(kv_item, event_type) ⇒ EventType
constructor
Instantiates a new EventType.
-
#lazy ⇒ Object
Creates a Lazy Enumerator for the EventList.
-
#perform(api_method, *args) ⇒ API::Response
Calls a method on the KeyValue's Collection's API Client, providing the event type.
-
#start(bound) ⇒ EventType::TimeSlice
Sets the inclusive start boundary for enumeration over events.
-
#take(count) ⇒ Array
Returns the first n items.
-
#to_s ⇒ Object
A pretty-printed string representation of the EventType.
Constructor Details
#initialize(kv_item, event_type) ⇒ EventType
Instantiates a new EventType.
49 50 51 52 |
# File 'lib/orchestrate/event_source.rb', line 49 def initialize(kv_item, event_type) @kv_item = kv_item @type = event_type.to_s end |
Instance Attribute Details
#kv_item ⇒ Orchestrate::KeyValue (readonly)
Returns The KeyValue this EventType is managing events for.
41 42 43 |
# File 'lib/orchestrate/event_source.rb', line 41 def kv_item @kv_item end |
#type ⇒ String (readonly)
Returns The name for the type of events this EventType manages.
44 45 46 |
# File 'lib/orchestrate/event_source.rb', line 44 def type @type end |
Instance Method Details
#<<(body) ⇒ Orchestrate::Event Also known as: push
Creates a new Event of the given type for the associated KeyValue.
89 90 91 |
# File 'lib/orchestrate/event_source.rb', line 89 def <<(body) TimeSlice.new(self).push(body) end |
#<=>(other) ⇒ nil, ...
Equivalent to String#<=>
. Comapres by key_value and type.
67 68 69 70 71 |
# File 'lib/orchestrate/event_source.rb', line 67 def <=>(other) return nil unless other.kind_of?(Orchestrate::EventType) return nil unless other.kv_item == kv_item other.type <=> type end |
#==(other) ⇒ true, false Also known as: eql?
Equivalent to String#==
. Compares by KeyValue and Type.
57 58 59 60 61 |
# File 'lib/orchestrate/event_source.rb', line 57 def ==(other) other.kind_of?(Orchestrate::EventType) && \ other.kv_item == kv_item && \ other.type == type end |
#[](bounds) ⇒ Object
Instantiates a new EventType::List with the given bounds. Can be used to access single events or create events with a specific timestamp.
106 107 108 |
# File 'lib/orchestrate/event_source.rb', line 106 def [](bounds) TimeSlice.new(self, bounds) end |
#after(bound) ⇒ EventType::TimeSlice
Sets the exclusive start boundary for enumeration over events. Overwrites any value given to #start
150 151 152 |
# File 'lib/orchestrate/event_source.rb', line 150 def after(bound) TimeSlice.new(self).after(bound) end |
#before(bound) ⇒ EventType::TimeSlice
Sets the exclusive end boundary for enumeration over events. Overwrites any value given to #end
158 159 160 |
# File 'lib/orchestrate/event_source.rb', line 158 def before(bound) TimeSlice.new(self).before(bound) end |
#each {|event| ... } ⇒ Object
Iterates over events belonging to the KeyValue of the specified Type. Used as the basis for enumerable methods. Events are provided in reverse chronological order by timestamp and ordinal value.
119 120 121 |
# File 'lib/orchestrate/event_source.rb', line 119 def each(&block) TimeSlice.new(self).each(&block) end |
#end(bound) ⇒ EventType::TimeSlice
Sets the inclusive end boundary for enumeration over events. Overwrites any value given to #before
166 167 168 |
# File 'lib/orchestrate/event_source.rb', line 166 def end(bound) TimeSlice.new(self).start(bound) end |
#lazy ⇒ Object
Creates a Lazy Enumerator for the EventList. If called inside the app's
#in_parallel
block, will prefetch results.
126 127 128 |
# File 'lib/orchestrate/event_source.rb', line 126 def lazy TimeSlice.new(self).lazy end |
#perform(api_method, *args) ⇒ API::Response
Calls a method on the KeyValue's Collection's API Client, providing the event type.
82 83 84 |
# File 'lib/orchestrate/event_source.rb', line 82 def perform(api_method, *args) kv_item.perform(api_method, type, *args) end |
#start(bound) ⇒ EventType::TimeSlice
Sets the inclusive start boundary for enumeration over events. Overwrites any value given to #before.
142 143 144 |
# File 'lib/orchestrate/event_source.rb', line 142 def start(bound) TimeSlice.new(self).start(bound) end |
#take(count) ⇒ Array
Returns the first n items. Equivalent to Enumerable#take. Sets the limit
parameter on the query to Orchestrate, so we don't ask for more than is needed.
134 135 136 |
# File 'lib/orchestrate/event_source.rb', line 134 def take(count) TimeSlice.new(self).take(count) end |
#to_s ⇒ Object
Returns A pretty-printed string representation of the EventType.
74 75 76 |
# File 'lib/orchestrate/event_source.rb', line 74 def to_s "#<Orchestrate::EventType key_value=#{kv_item} type=#{type}>" end |