Sha256: e39c939d7f81afe3d3cf88386f01df83601c796dee54b81743cf3470b3a10818
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true module ActiveDelivery module Lines # AbstractNotifier line for Active Delivery. # # You must provide custom `resolver` to infer notifier class # (if String#safe_constantize is defined, we convert "*Delivery" -> "*Notifier"). # # Resolver is a callable object. class Notifier < ActiveDelivery::Lines::Base DEFAULT_RESOLVER = ->(name) { name.gsub(/Delivery$/, "Notifier").safe_constantize } def initialize(*) super @resolver = options[:resolver] end def resolve_class(name) resolver&.call(name) end def notify?(method_name) handler_class.action_methods.include?(method_name.to_s) end def notify_now(handler, mid, *args) handler.public_send(mid, *args).notify_now end def notify_later(handler, mid, *args) handler.public_send(mid, *args).notify_later end private attr_reader :resolver end # Only automatically register line when we can resolve the class # easily. if "".respond_to?(:safe_constantize) ActiveDelivery::Base.register_line :notifier, Notifier, resolver: Notifier::DEFAULT_RESOLVER end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
abstract_notifier-0.2.0 | lib/active_delivery/lines/notifier.rb |
abstract_notifier-0.1.1 | lib/active_delivery/lines/notifier.rb |