class Orchestrate::EventType

Manages events of a specific type that belong to a specific KeyValue item.

Attributes

kv_item[R]

@return [Orchestrate::KeyValue] The KeyValue this EventType is managing events for.

type[R]

@return [String] The name for the type of events this EventType manages.

Public Class Methods

new(kv_item, event_type) click to toggle source

Instantiates a new EventType. @param kv_item [Orchestrate::KeyValue] The KeyValue this EventType manages events for. @param event_type [#to_s] The type of events this EventType manages.

# File lib/orchestrate/event_source.rb, line 49
def initialize(kv_item, event_type)
  @kv_item = kv_item
  @type = event_type.to_s
end

Public Instance Methods

<<(body) click to toggle source

Creates a new Event of the given type for the associated KeyValue. @param body [#to_json] The value for the event. @return [Orchestrate::Event] The event that was created.

# File lib/orchestrate/event_source.rb, line 89
def <<(body)
  TimeSlice.new(self).push(body)
end
Also aliased as: push
<=>(other) click to toggle source

Equivalent to ‘String#<=>`. Comapres by key_value and type. @param other [Orchestrate::EventType] The EventType to compare against. @return [nil, -1, 0, 1]

# 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) click to toggle source

Equivalent to ‘String#==`. Compares by KeyValue and Type. @param other [Orchestrate::EventType] The EventType to compare against. @return [true, false]

# File lib/orchestrate/event_source.rb, line 57
def ==(other)
  other.kind_of?(Orchestrate::EventType) && \
    other.kv_item == kv_item && \
    other.type == type
end
Also aliased as: eql?
[](bounds) click to toggle source

Instantiates a new EventType::List with the given bounds. Can be used to access single events or create events with a specific timestamp. @param bounds [#to_s, Time, Date, Integer, Hash] The bounds value for the List. @see EventType::List#initialize @example Accessing an existing event by timestamp/ordinal

kv.events[:checkins][timestamp][1]

@example Creating an Event with a specified timestamp

kv.events[:checkins][Time.now - 3600] << {"place" => "home"}

@example Listing events within a time range

kv.events[:checkins][{before: Time.now - 3600, after: Time.now - 24 * 3600}].to_a
# equivalent to:
# kv.events[:checkins].before(Time.now - 3600).after(Time.now - 24 * 3600).to_a
# File lib/orchestrate/event_source.rb, line 106
def [](bounds)
  TimeSlice.new(self, bounds)
end
after(bound) click to toggle source

Sets the exclusive start boundary for enumeration over events. Overwrites any value given to start @param bound [Orchestrate::Event, Time, Date, Integer, to_s] The exclusive start of the event range. @return [EventType::TimeSlice]

# File lib/orchestrate/event_source.rb, line 150
def after(bound)
  TimeSlice.new(self).after(bound)
end
before(bound) click to toggle source

Sets the exclusive end boundary for enumeration over events. Overwrites any value given to end @param bound [Orchestrate::Event, Time, Date, Integer, to_s] The exclusive end of the event range. @return [EventType::TimeSlice]

# File lib/orchestrate/event_source.rb, line 158
def before(bound)
  TimeSlice.new(self).before(bound)
end
each(&block) click to toggle source

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. @overlaod each

@return Enumerator

@overload each(&block)

@yieldparam [Orchestrate::Event] event The Event item
# File lib/orchestrate/event_source.rb, line 119
def each(&block)
  TimeSlice.new(self).each(&block)
end
end(bound) click to toggle source

Sets the inclusive end boundary for enumeration over events. Overwrites any value given to before @param bound [Orchestrate::Event, Time, Date, Integer, to_s] The inclusive end of the event range. @return [EventType::TimeSlice]

# File lib/orchestrate/event_source.rb, line 166
def end(bound)
  TimeSlice.new(self).start(bound)
end
eql?(other)
Alias for: ==
lazy() click to toggle source

Creates a Lazy Enumerator for the EventList. If called inside the app’s ‘#in_parallel` block, will prefetch results. @return Enumerator::Lazy

# File lib/orchestrate/event_source.rb, line 126
def lazy
  TimeSlice.new(self).lazy
end
perform(api_method, *args) click to toggle source

Calls a method on the KeyValue’s Collection’s API Client, providing the event type. @param api_method [Symbol] The method on the client to call. @param args [#to_s, to_json, Hash] The remaining arguments for the specified method. @return [API::Response]

# File lib/orchestrate/event_source.rb, line 82
def perform(api_method, *args)
  kv_item.perform(api_method, type, *args)
end
push(body)
Alias for: <<
start(bound) click to toggle source

Sets the inclusive start boundary for enumeration over events. Overwrites any value given to before. @param bound [Orchestrate::Event, Time, Date, Integer, to_s] The inclusive start of the event range. @return [EventType::TimeSlice]

# File lib/orchestrate/event_source.rb, line 142
def start(bound)
  TimeSlice.new(self).start(bound)
end
take(count) click to toggle source

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. @param count [Integer] The number of events to limit to. @return [Array]

# File lib/orchestrate/event_source.rb, line 134
def take(count)
  TimeSlice.new(self).take(count)
end
to_s() click to toggle source

@return A pretty-printed string representation of the EventType

# File lib/orchestrate/event_source.rb, line 74
def to_s
  "#<Orchestrate::EventType key_value=#{kv_item} type=#{type}>"
end