Module: Ably::Modules::EventEmitter::ClassMethods

Defined in:
lib/ably/modules/event_emitter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#event_emitter_coerce_procObject (readonly)

Returns the value of attribute event_emitter_coerce_proc.



26
27
28
# File 'lib/ably/modules/event_emitter.rb', line 26

def event_emitter_coerce_proc
  @event_emitter_coerce_proc
end

Instance Method Details

#configure_event_emitter(options = {}) ⇒ Object

Configure included EventEmitter

Examples:

configure_event_emitter coerce_into: lambda { |event| event.to_sym }

Parameters:

Options Hash (options):

  • :coerce_into (Proc)

    A lambda/Proc that is used to coerce the event names for all events. This is useful to ensure the event names conform to a naming or type convention.



36
37
38
# File 'lib/ably/modules/event_emitter.rb', line 36

def configure_event_emitter(options = {})
  @event_emitter_coerce_proc = options[:coerce_into]
end

#inherited(subclass) ⇒ Object

Ensure @event_emitter_coerce_proc option is passed down to any classes that inherit the class with callbacks



41
42
43
44
# File 'lib/ably/modules/event_emitter.rb', line 41

def inherited(subclass)
  subclass.instance_variable_set('@event_emitter_coerce_proc', @event_emitter_coerce_proc) if defined?(@event_emitter_coerce_proc)
  super
end