Module: Volt::ClassEventable

Included in:
Model
Defined in:
lib/volt/reactive/class_eventable.rb

Overview

ClassEventable behaves like Eventable, except events can be bound with a class #on method. When triggered on an instance, the self in the block will be the instance it was triggered on. This allows classes to easy setup listeners.

Example:

class Post
  on(:create) do
    deny if owner?
  end
end

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/volt/reactive/class_eventable.rb', line 62

def self.included(base)
  base.class_attribute :__listeners__

  # Include the base eventable so the class can be triggered on
  base.send :include, Volt::Eventable
  base.send :extend, ClassMethods
  base.send :include, InstanceMethods
end