Class: Hyrax::EventStore Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/event_store.rb

Overview

This class is abstract.

The event store provides an interface to log numbered events into a storage system, e.g. a key-value store.

At the class level, we provide a `.create` method for logging event data with incrementing ids. Events have an “action” (a string description of the event), and a (numeric) timestamp. Clients SHOULD provide a timestamp that represnts the current application time (i.e. via `Hyrax::TimeService`); see `Hyrax::Event.create_now`.

At the instance level, events can be pushed by id onto a list of events for a given topic key, and fetched by the same topic. Initialize an instance with `.for('topic_key')` and use `#push(event_id)` to associate events with the topic.

Direct Known Subclasses

RedisEventStore

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ EventStore

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EventStore.

Parameters:

  • key (String)

62
63
64
# File 'lib/hyrax/event_store.rb', line 62

def initialize(key)
  @key = key
end

Class Method Details

.create(_action, _timestamp) ⇒ Integer

This method is abstract.
Note:

clients should consider using `Hyrax::Event` to manage events instead of directly interfacing with this method.

Returns the id of the event.

Parameters:

  • action (String)
  • timestamp (Integer)

    the time to log the event. usually now.

Returns:

  • (Integer)

    the id of the event

Raises:

  • (NotImplementedError)

42
43
44
45
# File 'lib/hyrax/event_store.rb', line 42

def create(_action, _timestamp)
  raise NotImplementedError, 'EventStore.create should be provided by ' \
                             'a concrete implementation'
end

.for(key) ⇒ Object

TODO:

this is really just an initializer; deprecate in favor of `.new`?

Parameters:

  • key (String)

53
54
55
# File 'lib/hyrax/event_store.rb', line 53

def for(key)
  new(key)
end

.loggerLogger

Returns:

  • (Logger)

See Also:


29
# File 'lib/hyrax/event_store.rb', line 29

delegate :logger, to: Hyrax

Instance Method Details

#fetch(_size) ⇒ Enumerable<Hash<Symbol, String>>

Parameters:

  • size (Integer)

Returns:

  • (Enumerable<Hash<Symbol, String>>)

Raises:

  • (NotImplementedError)

70
71
72
73
# File 'lib/hyrax/event_store.rb', line 70

def fetch(_size)
  raise NotImplementedError, 'EventStore#fetch should be provided by ' \
                             'a concrete implementation'
end

#push(_value) ⇒ void

This method returns an undefined value.

Adds a value to the end of a list identified by key

Parameters:

  • value (Integer)

Raises:

  • (NotImplementedError)

81
82
83
84
# File 'lib/hyrax/event_store.rb', line 81

def push(_value)
  raise NotImplementedError, 'EventStore#push should be provided by ' \
                             'a concrete implementation'
end