Class: Lurker::Spy
Defined Under Namespace
Classes: BlindError
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #endpoint_path ⇒ Object
- #extensions ⇒ Object
-
#initialize(options = {}, &block) ⇒ Spy
constructor
A new instance of Spy.
- #suffix ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Spy
Returns a new instance of Spy.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lurker/spy.rb', line 14 def initialize(={}, &block) @options = @block = block @service = if defined?(Rails) Service.new(Rails.root.join(DEFAULT_SERVICE_PATH).to_s, Rails.application.class.parent_name) else Service.default_service end end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
7 8 9 |
# File 'lib/lurker/spy.rb', line 7 def block @block end |
#request ⇒ Object
Returns the value of attribute request.
8 9 10 |
# File 'lib/lurker/spy.rb', line 8 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
8 9 10 |
# File 'lib/lurker/spy.rb', line 8 def response @response end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
7 8 9 |
# File 'lib/lurker/spy.rb', line 7 def service @service end |
Class Method Details
.current ⇒ Object
84 85 86 |
# File 'lib/lurker/spy.rb', line 84 def self.current Thread.current[:lurker_spy] end |
.enabled? ⇒ Boolean
80 81 82 |
# File 'lib/lurker/spy.rb', line 80 def self.enabled? current.present? end |
.on(options = {}, &block) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/lurker/spy.rb', line 73 def self.on(={}, &block) require 'lurker/spec_helper' unless defined? Lurker::SpecHelper (Thread.current[:lurker_spy] ||= new(, &block)).tap do |spy| spy.call end end |
Instance Method Details
#call ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lurker/spy.rb', line 25 def call @request = @response = nil # fill in while test @block.call.tap do |result| if @request && @response @service.verify!( verb, endpoint_path, payload, extensions, status, body ) @service.persist! if success?(result) end end end |
#endpoint_path ⇒ Object
39 40 41 |
# File 'lib/lurker/spy.rb', line 39 def endpoint_path [request.endpoint_path, suffix].compact.join('-') end |
#extensions ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lurker/spy.rb', line 43 def extensions extensions = { path_params: request.path_params, path_info: request.path_info, method: request.verb, suffix: suffix.to_s, } unless request.query_params.empty? extensions[:query_params] = request.query_params end extensions end |
#suffix ⇒ Object
56 57 58 59 60 |
# File 'lib/lurker/spy.rb', line 56 def suffix if (suffix = @options[:suffix]).is_a?(String) suffix.gsub(/[^[[:alnum:]]]/, '_') end end |