Module: OnStomp::Interfaces::EventManager::ClassMethods

Defined in:
lib/onstomp/interfaces/event_manager.rb

Overview

Mixin to allow includers to define custom event methods

Instance Method Summary (collapse)

Instance Method Details

- (Object) create_event_method(name)

Creates a convenience method for binding callbacks to the given event name.

Examples:

class ExampleClass
  include OnStomp::Interfaces::EventManager

  create_event_method :do_event
end

example_obj.do_event { |arg1, arg2| ... }

Parameters:

  • name (Symbol)


59
60
61
62
# File 'lib/onstomp/interfaces/event_manager.rb', line 59

def create_event_method name
  event_methods << name
  module_eval "def #{name}(&block); bind_event(:#{name}, block); end"
end

- (Object) create_event_methods(name, *prefixes)

Creates convenience methods for binding callbacks to the given event name with a set of prefixes.

Examples:

class ExampleClass
  include OnStomp::Interfaces::EventManager

  create_event_methods :some_event, :before, :during, :after
end

example_obj.before_some_event { |arg| ... }
example_obj.after_some_event { |arg| ... }
example_obj.during_some_event { |arg| ... }

Parameters:

  • name (Symbol)
  • prefixes (Symbol, Symbol, ...)

    (eg: :on, :before, :after)



78
79
80
81
# File 'lib/onstomp/interfaces/event_manager.rb', line 78

def create_event_methods name, *prefixes
  prefixes << :on if prefixes.empty?
  prefixes.each { |pre| create_event_method :#{pre}_#{name}" }
end

- (Array<Symbol>) event_methods

A convenient way to get a list of all of the event methods a class has defined for itself. Returns an array of event method names as symbols.

Returns:

  • (Array<Symbol>)


44
45
46
# File 'lib/onstomp/interfaces/event_manager.rb', line 44

def event_methods
  @event_methods ||= []
end