Class: Evidence::ActionParser
- Inherits:
-
Object
- Object
- Evidence::ActionParser
- Defined in:
- lib/evidence/action_parser.rb,
lib/evidence/rails_action_parser.rb
Instance Method Summary collapse
- #end_action?(msg) ⇒ Boolean
-
#initialize(pid, message, action_patterns) ⇒ ActionParser
constructor
A new instance of ActionParser.
- #parse_action_logs(logs) ⇒ Object
- #request(msg) ⇒ Object
- #response(msg) ⇒ Object
- #start_action?(msg) ⇒ Boolean
- #to_hash(m) ⇒ Object
- #to_proc ⇒ Object
Constructor Details
#initialize(pid, message, action_patterns) ⇒ ActionParser
Returns a new instance of ActionParser.
4 5 6 7 8 |
# File 'lib/evidence/action_parser.rb', line 4 def initialize(pid, , action_patterns) @pid, @message = pid, @processes = Hash.new @start_action_pattern, @end_action_pattern = action_patterns[:start], action_patterns[:end] end |
Instance Method Details
#end_action?(msg) ⇒ Boolean
35 36 37 |
# File 'lib/evidence/action_parser.rb', line 35 def end_action?(msg) msg =~ @end_action_pattern end |
#parse_action_logs(logs) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/evidence/action_parser.rb', line 27 def parse_action_logs(logs) { request: request(@message[logs[0]]), response: response(@message[logs[-1]]), logs: logs } end |
#request(msg) ⇒ Object
43 44 45 |
# File 'lib/evidence/action_parser.rb', line 43 def request(msg) to_hash(@start_action_pattern.match(msg)) end |
#response(msg) ⇒ Object
47 48 49 |
# File 'lib/evidence/action_parser.rb', line 47 def response(msg) to_hash(@end_action_pattern.match(msg)) end |
#start_action?(msg) ⇒ Boolean
39 40 41 |
# File 'lib/evidence/action_parser.rb', line 39 def start_action?(msg) msg =~ @start_action_pattern end |
#to_hash(m) ⇒ Object
51 52 53 |
# File 'lib/evidence/action_parser.rb', line 51 def to_hash(m) Hash[m.names.map(&:to_sym).zip(m.captures)] end |
#to_proc ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/evidence/action_parser.rb', line 10 def to_proc lambda do |log| pid = @pid[log] if @processes.has_key?(pid) @processes[pid] << log if end_action?(@message[log]) parse_action_logs(@processes.delete(pid)) end else if start_action?(@message[log]) @processes[pid] = [log] end nil end end end |