class Sqreen::CB
Constants
- DEFAULT_PRIORITY
Callback class.
Three methods can be defined:
-
pre(*args, &block) To be called prior to the hooked method.
-
post(return_value, *args, &block) To be called after the hooked method. The return_value argument is the value returned by the hooked method.
-
failing(exception, …) To be called when the method raise
The method pre, post and exception may return nil or a Hash.
- nil: the original method is called and the callback has no further effect - { :status => :skip }: we skip the original method call - { :status => :raise}: - nil: the original return value is returned, as if coallback had no effect - { :status => :raise}: - { :status => :override }: - nil: reraise - { :status => :reraise }: reraise - { :status => :override }: eat exception - { :retry => :retry }: try the block again CB can also declare that they are whitelisted and should not be run at the moment.
-
Attributes
klass[R]
method[R]
overtimeable[R]
Public Class Methods
new(klass, method)
click to toggle source
# File lib/sqreen/cb.rb, line 44 def initialize(klass, method) @method = method @klass = klass @has_pre = respond_to? :pre @has_post = respond_to? :post @has_failing = respond_to? :failing @overtimeable = false raise(Sqreen::Exception, 'No callback provided') unless @has_pre || @has_post || @has_failing end
Public Instance Methods
failing?()
click to toggle source
# File lib/sqreen/cb.rb, line 73 def failing? @has_failing end
framework()
click to toggle source
# File lib/sqreen/cb.rb, line 86 def framework nil end
overtime!()
click to toggle source
# File lib/sqreen/cb.rb, line 81 def overtime! Sqreen.log.debug { "#{self} is overtime!" } @overtimeable end
post?()
click to toggle source
# File lib/sqreen/cb.rb, line 69 def post? @has_post end
pre?()
click to toggle source
# File lib/sqreen/cb.rb, line 65 def pre? @has_pre end
priority()
click to toggle source
the lower, the closer to the beginning of the list
# File lib/sqreen/cb.rb, line 61 def priority DEFAULT_PRIORITY end
to_s()
click to toggle source
# File lib/sqreen/cb.rb, line 77 def to_s format('#<%s: %s.%s>', self.class, @klass, @method) end
whitelisted?()
click to toggle source
# File lib/sqreen/cb.rb, line 56 def whitelisted? false end