class Fragmentary::Subscription

Attributes

record[RW]
subscriber[R]

Public Class Methods

new(publisher, subscriber) click to toggle source
# File lib/fragmentary/subscription.rb, line 52
def initialize(publisher, subscriber)
  @subscriber = subscriber
  Proxy.fetch(publisher.name).register(self)
end

Public Instance Methods

after_create(record) click to toggle source
# File lib/fragmentary/subscription.rb, line 57
def after_create(record)
  call_method(:"create_#{record.class.model_name.param_key}_successful", record)
end
after_destroy(record) click to toggle source
# File lib/fragmentary/subscription.rb, line 65
def after_destroy(record)
  # An ActiveSupport::Callbacks :after_destroy callback is set on the eigenclass of each individual
  # subscription in Fragment.set_record_type in order to clean up fragments whose AR records are destroyed.
  run_callbacks :after_destroy do
    @record = record
    call_method(:"destroy_#{record.class.model_name.param_key}_successful", record)
  end
end
after_update(record) click to toggle source
# File lib/fragmentary/subscription.rb, line 61
def after_update(record)
  call_method(:"update_#{record.class.model_name.param_key}_successful", record)
end

Private Instance Methods

call_method(method, record) click to toggle source
# File lib/fragmentary/subscription.rb, line 75
def call_method(method, record)
  Rails.logger.info "***** Calling #{method.inspect} on #{subscriber.client.name} with record #{record.class.name} #{record.id}"
  start = Time.now
  subscriber.public_send(method, record) if subscriber.respond_to? method
  finish = Time.now
  Rails.logger.info "***** #{method.inspect} duration: #{(finish - start) * 1000}ms\n\n"
end