Class: Sqreen::CB
- Inherits:
-
Object
- Object
- Sqreen::CB
- Defined in:
- lib/sqreen/cb.rb
Direct Known Subclasses
DefaultCB, FrameworkCB, Rules::RunUserActions, RunWhenCalledCB
Constant Summary collapse
- 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.
-
100
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#overtimeable ⇒ Object
readonly
Returns the value of attribute overtimeable.
Instance Method Summary collapse
- #failing? ⇒ Boolean
- #framework ⇒ Object
-
#initialize(klass, method) ⇒ CB
constructor
A new instance of CB.
- #overtime! ⇒ Object
- #post? ⇒ Boolean
- #pre? ⇒ Boolean
-
#priority ⇒ Object
the lower, the closer to the beginning of the list.
- #to_s ⇒ Object
- #whitelisted? ⇒ Boolean
Constructor Details
#initialize(klass, method) ⇒ CB
Returns a new instance of CB.
44 45 46 47 48 49 50 51 52 53 54 |
# 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 |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
41 42 43 |
# File 'lib/sqreen/cb.rb', line 41 def klass @klass end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
41 42 43 |
# File 'lib/sqreen/cb.rb', line 41 def method @method end |
#overtimeable ⇒ Object (readonly)
Returns the value of attribute overtimeable.
42 43 44 |
# File 'lib/sqreen/cb.rb', line 42 def overtimeable @overtimeable end |
Instance Method Details
#failing? ⇒ Boolean
73 74 75 |
# File 'lib/sqreen/cb.rb', line 73 def failing? @has_failing end |
#framework ⇒ Object
86 87 88 |
# File 'lib/sqreen/cb.rb', line 86 def framework nil end |
#overtime! ⇒ Object
81 82 83 84 |
# File 'lib/sqreen/cb.rb', line 81 def overtime! Sqreen.log.debug { "#{self} is overtime!" } @overtimeable end |
#post? ⇒ Boolean
69 70 71 |
# File 'lib/sqreen/cb.rb', line 69 def post? @has_post end |
#pre? ⇒ Boolean
65 66 67 |
# File 'lib/sqreen/cb.rb', line 65 def pre? @has_pre end |
#priority ⇒ Object
the lower, the closer to the beginning of the list
61 62 63 |
# File 'lib/sqreen/cb.rb', line 61 def priority DEFAULT_PRIORITY end |
#to_s ⇒ Object
77 78 79 |
# File 'lib/sqreen/cb.rb', line 77 def to_s format('#<%s: %s.%s>', self.class, @klass, @method) end |
#whitelisted? ⇒ Boolean
56 57 58 |
# File 'lib/sqreen/cb.rb', line 56 def whitelisted? false end |