class Maitredee::Subscriber::SubscriberProxy

Attributes

subscriber[R]

Public Class Methods

new(subscriber) click to toggle source
# File lib/maitredee/subscriber.rb, line 52
def initialize(subscriber)
  @subscriber = subscriber
end

Public Instance Methods

default_event(to:) click to toggle source

configure a default method to be called if not specifically configured to be listened to @param event_name [#to_s] @param to [#to_sym] must be valid method name

# File lib/maitredee/subscriber.rb, line 79
def default_event(to:)
  subscriber.event_configs.default = EventConfig.new(
    event_name: nil,
    action: to.to_s
  )
end
event(event_name, to: nil) click to toggle source

configure subscriber to listen to event_name @param event_name [nil, to_s] @param to [#to_s] must be valid method name

# File lib/maitredee/subscriber.rb, line 59
def event(event_name, to: nil)
  if event_name.nil? && to.nil?
    raise ArgumentError, "event_name and to: cannot both be nil"
  end

  if event_name.present? && /[@$"]/ =~ event_name.to_sym.inspect && to.nil?
    raise ArgumentError, "'#{event_name}' is not a valid method name, you must set the 'to' parameter"
  end

  event_config = EventConfig.new(
    event_name: event_name.to_s,
    action: (to || event_name).to_s
  )

  subscriber.event_configs[event_config.event_name] = event_config
end