Module: Crossbeam::Callbacks::ClassMethods

Defined in:
lib/crossbeam/callbacks.rb

Overview

Methods to load in the service object as class methods

Instance Method Summary collapse

Instance Method Details

#after(*callbacks) { ... } ⇒ Void

Add callback ‘after` method or block

Parameters:

  • callbacks (Hash)

Yields:

  • An optional block to instance_exec(&block) || instance_eval(&block)

Returns:

  • (Void)


37
38
39
40
# File 'lib/crossbeam/callbacks.rb', line 37

def after(*callbacks, &block)
  callbacks << block if block
  callbacks.each { |callback| after_callbacks << callback }
end

#after_callbacksArray

Create a list of ‘after` callback methods and/or blocks

Returns:

  • (Array)


60
61
62
# File 'lib/crossbeam/callbacks.rb', line 60

def after_callbacks
  @after_callbacks ||= []
end

#before(*callbacks) { ... } ⇒ Void

Add callback ‘before` method or block

Parameters:

  • callbacks (Hash)

Yields:

  • An optional block to instance_exec(&block) || instance_eval(&block)

Returns:

  • (Void)


27
28
29
30
# File 'lib/crossbeam/callbacks.rb', line 27

def before(*callbacks, &block)
  callbacks << block if block
  callbacks.each { |callback| before_callbacks << callback }
end

#before_callbacksArray

Create a list of ‘before` callback methods and/or blocks

Returns:

  • (Array)


67
68
69
# File 'lib/crossbeam/callbacks.rb', line 67

def before_callbacks
  @before_callbacks ||= []
end

#run_after_callbacksVoid

Call and run all callbacks after ‘#call` has ran

Returns:

  • (Void)


53
54
55
# File 'lib/crossbeam/callbacks.rb', line 53

def run_after_callbacks
  run_callbacks(after_callbacks)
end

#run_before_callbacksVoid

Call all callbacks before ‘#call` is referenced (methods, blocks, etc.)

Returns:

  • (Void)


45
46
47
48
# File 'lib/crossbeam/callbacks.rb', line 45

def run_before_callbacks
  # run_callbacks(self.class.before_callbacks)
  run_callbacks(before_callbacks)
end

#run_callbacks(callbacks) ⇒ Void

Loopthrough and run all the classes listed callback methods

Parameters:

  • callbacks (Array<String, Symbol>)

    a list of methods to be called

Returns:

  • (Void)


75
76
77
# File 'lib/crossbeam/callbacks.rb', line 75

def run_callbacks(callbacks)
  callbacks.each { |callback| run_callback(callback) }
end