Class: Citrus::Common::Service::FilterService
- Inherits:
-
Object
- Object
- Citrus::Common::Service::FilterService
- Defined in:
- lib/citrus/common/service/filter_service.rb
Overview
FilterService
Instance Method Summary collapse
-
#after(filter) ⇒ Object
Add after filter into the filter chain.
-
#after_filter(err, msg, session, resp, &block) ⇒ Object
Do the after filter chain.
-
#before(filter) ⇒ Object
Add before filter into the filter chain.
-
#before_filter(msg, session, &block) ⇒ Object
Do the before filter chain.
-
#initialize ⇒ FilterService
constructor
Initialize the service.
Constructor Details
#initialize ⇒ FilterService
Initialize the service
19 20 21 22 |
# File 'lib/citrus/common/service/filter_service.rb', line 19 def initialize @befores = [] @afters = [] end |
Instance Method Details
#after(filter) ⇒ Object
Add after filter into the filter chain
34 35 36 |
# File 'lib/citrus/common/service/filter_service.rb', line 34 def after filter @afters.unshift filter end |
#after_filter(err, msg, session, resp, &block) ⇒ Object
Do the after filter chain
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/citrus/common/service/filter_service.rb', line 69 def after_filter err, msg, session, resp, &block index = 0 next_p = Proc.new { |err| if index >= @afters.length block_given? and yield err return end handler = @afters[index] index += 1 if handler.respond_to? :call handler.call err, msg, session, resp, &next_p else next_p.call Exception.new 'invalid after filter' end } next_p.call err end |
#before(filter) ⇒ Object
Add before filter into the filter chain
27 28 29 |
# File 'lib/citrus/common/service/filter_service.rb', line 27 def before filter @befores << filter end |
#before_filter(msg, session, &block) ⇒ Object
Do the before filter chain
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/citrus/common/service/filter_service.rb', line 42 def before_filter msg, session, &block index = 0 next_p = Proc.new { |err, resp, args| if err || index >= @befores.length block_given? and yield err, resp, args return end handler = @befores[index] index += 1 if handler.respond_to? :call handler.call msg, session, &next_p else next_p.call Exception.new 'invalid before filter' end } next_p.call end |