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
-
#create_event_method(name) ⇒ Object
Creates a convenience method for binding callbacks to the given event name.
-
#create_event_methods(name, *prefixes) ⇒ Object
Creates convenience methods for binding callbacks to the given event name with a set of prefixes.
-
#event_methods ⇒ Array<Symbol>
A convenient way to get a list of all of the event methods a class has defined for itself.
Instance Method Details
#create_event_method(name) ⇒ Object
Creates a convenience method for binding callbacks to the given event name.
53 54 55 56 |
# File 'lib/onstomp/interfaces/event_manager.rb', line 53 def create_event_method name event_methods << name module_eval "def #{name}(&block); bind_event(:#{name}, block); end" end |
#create_event_methods(name, *prefixes) ⇒ Object
Creates convenience methods for binding callbacks to the given event name with a set of prefixes.
72 73 74 75 |
# File 'lib/onstomp/interfaces/event_manager.rb', line 72 def create_event_methods name, *prefixes prefixes << :on if prefixes.empty? prefixes.each { |pre| create_event_method :"#{pre}_#{name}" } end |
#event_methods ⇒ Array<Symbol>
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.
38 39 40 |
# File 'lib/onstomp/interfaces/event_manager.rb', line 38 def event_methods @event_methods ||= [] end |