Class: EventMachine::Http::MonitorFactory::MockingFileOutputter
- Inherits:
-
FileOutputter
- Object
- FileOutputter
- EventMachine::Http::MonitorFactory::MockingFileOutputter
- Defined in:
- lib/em-http-monitor.rb
Direct Known Subclasses
Defined Under Namespace
Classes: MockingData
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #find_mock(verb, uri, host) ⇒ Object
-
#initialize(file) ⇒ MockingFileOutputter
constructor
A new instance of MockingFileOutputter.
Methods inherited from FileOutputter
Constructor Details
#initialize(file) ⇒ MockingFileOutputter
Returns a new instance of MockingFileOutputter.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/em-http-monitor.rb', line 203 def initialize(file) @file = file if File.exist?(file) @mock_data = File.read(file).each_line.inject([]) do |hash, line| data = JSON.parse(line) if entry = hash.assoc(data['id']) entry = entry.last else entry = MockingData.new hash << [data['id'], entry] end case data['mode'] when 'send' entry.sent << data['data'] when 'receive' entry.received << data['data'] else raise end hash end end super end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
192 193 194 |
# File 'lib/em-http-monitor.rb', line 192 def file @file end |
Instance Method Details
#find_mock(verb, uri, host) ⇒ Object
228 229 230 231 232 |
# File 'lib/em-http-monitor.rb', line 228 def find_mock(verb, uri, host) if @mock_data and matching_data = @mock_data.find{ |d| d.last.sent[/^#{Regexp.quote(verb.to_s.upcase)} #{Regexp.quote(uri)} HTTP\/1\.[01][\r\n]/] and d.last.sent[/(Host:\s*#{Regexp.quote(host)})[\r\n]/] } @mock_data.delete(matching_data).last.received end end |