Class: Celluloid::Notifications::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/notifications.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor, pattern, method) ⇒ Subscriber

Returns a new instance of Subscriber.


68
69
70
71
72
# File 'lib/celluloid/notifications.rb', line 68

def initialize(actor, pattern, method)
  @actor = actor
  @pattern = pattern
  @method = method
end

Instance Attribute Details

#actorObject

Returns the value of attribute actor


66
67
68
# File 'lib/celluloid/notifications.rb', line 66

def actor
  @actor
end

#methodObject

Returns the value of attribute method


66
67
68
# File 'lib/celluloid/notifications.rb', line 66

def method
  @method
end

#patternObject

Returns the value of attribute pattern


66
67
68
# File 'lib/celluloid/notifications.rb', line 66

def pattern
  @pattern
end

Instance Method Details

#matches?(subscriber_or_pattern) ⇒ Boolean

Returns:

  • (Boolean)

85
86
87
88
# File 'lib/celluloid/notifications.rb', line 85

def matches?(subscriber_or_pattern)
  self === subscriber_or_pattern ||
    @pattern && @pattern === subscriber_or_pattern
end

#publish(pattern, *args) ⇒ Object


74
75
76
77
78
79
# File 'lib/celluloid/notifications.rb', line 74

def publish(pattern, *args)
  actor.async method, pattern, *args
rescue DeadActorError
  # TODO: needs a tests
  # Bad shutdown logic. Oh well....
end

#subscribed_to?(pattern) ⇒ Boolean

Returns:

  • (Boolean)

81
82
83
# File 'lib/celluloid/notifications.rb', line 81

def subscribed_to?(pattern)
  !pattern || @pattern === pattern.to_s || @pattern === pattern
end