Class: Renalware::Broadcasting::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/renalware/broadcasting.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass_name, async: false) ⇒ Subscriber

Returns a new instance of Subscriber.



14
15
16
17
# File 'app/models/concerns/renalware/broadcasting.rb', line 14

def initialize(klass_name, async: false)
  @klass_name = klass_name
  @async = async
end

Instance Attribute Details

#asyncObject (readonly) Also known as: async?

Returns the value of attribute async.



11
12
13
# File 'app/models/concerns/renalware/broadcasting.rb', line 11

def async
  @async
end

#klass_nameObject (readonly)

Returns the value of attribute klass_name.



11
12
13
# File 'app/models/concerns/renalware/broadcasting.rb', line 11

def klass_name
  @klass_name
end

Instance Method Details

#instanceObject

Note that when using the wisper-activejob gem (so we can use delayed_job for instance) we subscribe the class not an instance, and the subscriber must have class methods matching the event names it wants to handle. github.com/krisleech/wisper-activejob



23
24
25
# File 'app/models/concerns/renalware/broadcasting.rb', line 23

def instance
  async? ? klass : klass.new
end

#klassObject



27
28
29
# File 'app/models/concerns/renalware/broadcasting.rb', line 27

def klass
  klass_name.to_s.constantize
end