Module: Jsm::Callbacks::ClassMethods

Defined in:
lib/jsm/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#after(context, &block) ⇒ Object

this method is to register a ‘after callback` to a jsm_callbacks



28
29
30
31
32
# File 'lib/jsm/callbacks.rb', line 28

def after(context, &block)
  pre_after(context, &block)
  callback = Jsm::Callbacks::Callback.new(:after, &block)
  self.jsm_callbacks[context].insert_callback(callback)
end

#before(context, &block) ⇒ Object

this method is to register a ‘before callback` to a jsm_callbacks



19
20
21
22
23
24
25
# File 'lib/jsm/callbacks.rb', line 19

def before(context, &block)

  pre_before(context, &block)
  callback = Jsm::Callbacks::Callback.new(:before, &block)
  jsm_callbacks[context] ||= Jsm::Callbacks::Chain.new(context)
  jsm_callbacks[context].insert_callback(callback)
end

#jsm_callbacksObject



7
8
9
# File 'lib/jsm/callbacks.rb', line 7

def jsm_callbacks
  @jsm_callbacks ||= Jsm::Callbacks::ChainCollection.new(self)
end

#pre_after(context, &block) ⇒ Object

override this to do something before method ‘after`



15
16
# File 'lib/jsm/callbacks.rb', line 15

def pre_after(context, &block)
end

#pre_before(context, &block) ⇒ Object

override this to do something before method ‘before`



11
12
# File 'lib/jsm/callbacks.rb', line 11

def pre_before(context, &block)
end

#run_callback(context, *args, &block) ⇒ Object



34
35
36
# File 'lib/jsm/callbacks.rb', line 34

def run_callback(context, *args, &block)
  self.jsm_callbacks[context].compile(*args, &block)
end