Class: PubSub::Register

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/pub_sub/register.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegister

Returns a new instance of Register.



9
10
11
12
# File 'lib/pub_sub/register.rb', line 9

def initialize
  @enabled = true
  super
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



7
8
9
# File 'lib/pub_sub/register.rb', line 7

def enabled
  @enabled
end

Class Method Details

.disableObject



19
20
21
# File 'lib/pub_sub/register.rb', line 19

def disable
  instance.enabled = false
end

.disabled?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/pub_sub/register.rb', line 31

def disabled?
  !instance.enabled
end

.enableObject



15
16
17
# File 'lib/pub_sub/register.rb', line 15

def enable
  instance.enabled = true
end

.enabled?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/pub_sub/register.rb', line 23

def enabled?
  if instance.enabled.nil?
    instance.enabled = true
  end

  instance.enabled
end

.publish(*args, &block) ⇒ Object



35
36
37
38
39
# File 'lib/pub_sub/register.rb', line 35

def publish(*args, &block)
  return if disabled?

  ActiveSupport::Notifications.publish(*args, &block)
end

.subscribe(*args, &block) ⇒ Object



41
42
43
# File 'lib/pub_sub/register.rb', line 41

def subscribe(*args, &block)
  ActiveSupport::Notifications.subscribe(*args, &block)
end