Class: Informator::Reporter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/informator/reporter.rb

Overview

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

Builds, collects and publishes events to selected subscribers

Examples:

reporter = Reporter.new
reporter.events # => []

reporter.remember :success
reporter.events # => [#<Event @type=:success @attributes={} @messages=[]>]

# this will call subscriber.notify for any event
reporter.notify subscriber
reporter.events # => []

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReporter

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 Reporter.



23
24
25
26
# File 'lib/informator/reporter.rb', line 23

def initialize
  @events = []
  freeze # freezes the instance, but left events mutable!
end

Instance Attribute Details

#eventsArray<Informator::Event> (readonly)

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 the list of registered events that havent’b been published yet.

Returns:

  • (Array<Informator::Event>)

    the list of registered events that havent’b been published yet



31
32
33
# File 'lib/informator/reporter.rb', line 31

def events
  @events
end

Instance Method Details

#notify(*subscribers) ⇒ Array<Informator::Event>

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.

Notifies subscribers on events registered since the last notification

Mutates [#events] by excluding all events having been published.

Parameters:

Returns:



54
55
56
# File 'lib/informator/reporter.rb', line 54

def notify(*subscribers)
  events.dup.each { publish subscribers.flatten }
end

#remember(type, messages, attributes) ⇒ self

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.

Registers the event to be published to subscribers

Returns:

  • (self)

    itself



40
41
42
43
44
# File 'lib/informator/reporter.rb', line 40

def remember(*args)
  events << Event.new(*args)

  self
end