Module: Wisper

Defined in:
lib/wisper/global_listeners.rb,
lib/wisper.rb,
lib/wisper/version.rb,
lib/wisper/publisher.rb,
lib/wisper/configuration.rb,
lib/wisper/rspec/matchers.rb,
lib/wisper/registration/block.rb,
lib/wisper/registration/object.rb,
lib/wisper/temporary_listeners.rb,
lib/wisper/registration/registration.rb,
lib/wisper/broadcasters/send_broadcaster.rb,
lib/wisper/broadcasters/logger_broadcaster.rb

Overview

Provides a way of wrapping another broadcaster with logging

Defined Under Namespace

Modules: Broadcasters, Publisher, RSpec Classes: BlockRegistration, Configuration, GlobalListeners, ObjectRegistration, Registration, TemporaryListeners

Constant Summary collapse

VERSION =
"1.6.1"

Class Method Summary collapse

Class Method Details

.add_listener(listener, options = {}) ⇒ Object


24
25
26
27
# File 'lib/wisper.rb', line 24

def self.add_listener(listener, options = {})
  warn "[DEPRECATION] `use Wisper.subscribe` instead of `Wisper.add_listener`"
  self.subscribe(listener, options)
end

.clearObject


55
56
57
# File 'lib/wisper.rb', line 55

def self.clear
  GlobalListeners.clear
end

.configurationObject


63
64
65
# File 'lib/wisper.rb', line 63

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:


59
60
61
# File 'lib/wisper.rb', line 59

def self.configure
  yield(configuration)
end

.included(base) ⇒ Object


14
15
16
17
# File 'lib/wisper.rb', line 14

def self.included(base)
  warn "[DEPRECATION] `include Wisper::Publisher` instead of `include Wisper`"
  base.class_eval { include Wisper::Publisher  }
end

.publisherObject


51
52
53
# File 'lib/wisper.rb', line 51

def self.publisher
  Publisher
end

.setupObject


67
68
69
70
71
# File 'lib/wisper.rb', line 67

def self.setup
  configure do |config|
    config.broadcaster(:default, Broadcasters::SendBroadcaster.new)
  end
end

.subscribe(*args, &block) ⇒ Object

Examples:

Wisper.subscribe(AuditRecorder.new)

Wisper.subscribe(AuditRecorder.new, StatsRecorder.new)

Wisper.subscribe(AuditRecorder.new, on: 'order_created')

Wisper.subscribe(AuditRecorder.new, scope: 'MyPublisher')

Wisper.subscribe(AuditRecorder.new, StatsRecorder.new) do
  # ..
end

43
44
45
46
47
48
49
# File 'lib/wisper.rb', line 43

def self.subscribe(*args, &block)
  if block_given?
    TemporaryListeners.subscribe(*args, &block)
  else
    GlobalListeners.subscribe(*args)
  end
end

.with_listeners(*args, &block) ⇒ Object


19
20
21
22
# File 'lib/wisper.rb', line 19

def self.with_listeners(*args, &block)
  warn "[DEPRECATION] `use Wisper.subscribe` instead of `Wisper.with_listeners`"
  self.subscribe(*args, &block)
end