Class: InspectRequest::Checker
- Inherits:
-
Object
- Object
- InspectRequest::Checker
- Defined in:
- lib/inspect_request.rb
Overview
Checker class
Class Attribute Summary collapse
-
.session ⇒ Object
readonly
Returns the value of attribute session.
-
.started ⇒ Object
readonly
Returns the value of attribute started.
Class Method Summary collapse
-
.shutdown ⇒ Object
Shutdown proxy.
-
.start ⇒ Object
Start the proxy.
Instance Method Summary collapse
-
#configure(&block) ⇒ Object
Configure proxy.
-
#fulfilled? ⇒ Boolean
did our verification ever fulfilled?.
-
#initialize ⇒ Checker
constructor
A new instance of Checker.
- #started? ⇒ Boolean
-
#verify(&block) ⇒ Object
block should return true/false given an
req(webrick request instance) ===== Examples.
Constructor Details
#initialize ⇒ Checker
Returns a new instance of Checker.
16 17 18 19 20 21 22 23 24 |
# File 'lib/inspect_request.rb', line 16 def initialize @results = [] @verifier_block = proc {} self.class.start self.class.session.on_request do |req| track_result @verifier_block.call req.clone end end |
Class Attribute Details
.session ⇒ Object (readonly)
Returns the value of attribute session.
12 13 14 |
# File 'lib/inspect_request.rb', line 12 def session @session end |
.started ⇒ Object (readonly)
Returns the value of attribute started.
13 14 15 |
# File 'lib/inspect_request.rb', line 13 def started @started end |
Class Method Details
.shutdown ⇒ Object
Shutdown proxy
37 38 39 40 |
# File 'lib/inspect_request.rb', line 37 def self.shutdown @session.shutdown if @started @started = false end |
.start ⇒ Object
Start the proxy. No need to do this unless you’ve explicitely shut it down
27 28 29 30 31 32 33 34 |
# File 'lib/inspect_request.rb', line 27 def self.start return if @started @session ||= Ritm::Session.new @session.start @started = true trap('INT') { Checker.shutdown } trap('TERM') { Checker.shutdown } end |
Instance Method Details
#configure(&block) ⇒ Object
Configure proxy. It will also auto-restart the proxy
Examples
foo = InspectRequest::Checker.new
foo.configure do
proxy[:bind_port] = 7070
end
69 70 71 72 73 |
# File 'lib/inspect_request.rb', line 69 def configure(&block) self.class.session.send(:configure, &block) self.class.session.shutdown self.class.session.start end |
#fulfilled? ⇒ Boolean
did our verification ever fulfilled?
57 58 59 60 61 |
# File 'lib/inspect_request.rb', line 57 def fulfilled? res = @results.any? # any true? @results.clear res end |
#started? ⇒ Boolean
42 43 44 |
# File 'lib/inspect_request.rb', line 42 def started? self.class.started end |
#verify(&block) ⇒ Object
block should return true/false given an req (webrick request instance)
Examples
foo.verify do |req|
req.host == 'example.org'
end
52 53 54 |
# File 'lib/inspect_request.rb', line 52 def verify(&block) @verifier_block = block end |