Sha256: b3864193174f01045b5d7ec1ee39090ac01e23eea318851c6cc572b2fb6cd96e

Contents?: true

Size: 827 Bytes

Versions: 29

Compression:

Stored size: 827 Bytes

Contents

# frozen_string_literal: true
module Hyrax
  # A mixin module intended to provide an interface into creating the paper trail
  # of activity on the target model of the mixin.
  #
  # @see Hyrax::Event
  module WithEvents
    def stream
      Nest.new(event_class)[to_param]
    end

    # @return [String]
    def event_class
      model_name.name
    end

    ##
    # @param [Integer] size  the maximum number of events to fetch from the log.
    #   Offset by 1; to get one event, use `0`, for two, use `1`, etc...
    #   `-1` gives all events.
    def events(size = -1)
      event_stream.fetch(size)
    end

    def log_event(event_id)
      event_stream.push(event_id)
    end

    private

    def event_store
      RedisEventStore
    end

    def event_stream
      event_store.for(stream[:event])
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/models/concerns/hyrax/with_events.rb
hyrax-5.0.4 app/models/concerns/hyrax/with_events.rb
hyrax-5.0.3 app/models/concerns/hyrax/with_events.rb
hyrax-5.0.2 app/models/concerns/hyrax/with_events.rb
hyrax-5.0.1 app/models/concerns/hyrax/with_events.rb
hyrax-5.0.0 app/models/concerns/hyrax/with_events.rb
hyrax-5.0.0.rc3 app/models/concerns/hyrax/with_events.rb
hyrax-5.0.0.rc2 app/models/concerns/hyrax/with_events.rb
hyrax-5.0.0.rc1 app/models/concerns/hyrax/with_events.rb
hyrax-3.6.0 app/models/concerns/hyrax/with_events.rb
hyrax-4.0.0 app/models/concerns/hyrax/with_events.rb
hyrax-4.0.0.rc3 app/models/concerns/hyrax/with_events.rb
hyrax-4.0.0.rc2 app/models/concerns/hyrax/with_events.rb
hyrax-4.0.0.rc1 app/models/concerns/hyrax/with_events.rb
hyrax-3.5.0 app/models/concerns/hyrax/with_events.rb
hyrax-4.0.0.beta2 app/models/concerns/hyrax/with_events.rb
hyrax-3.4.2 app/models/concerns/hyrax/with_events.rb
hyrax-4.0.0.beta1 app/models/concerns/hyrax/with_events.rb
hyrax-3.4.1 app/models/concerns/hyrax/with_events.rb
hyrax-3.4.0 app/models/concerns/hyrax/with_events.rb