Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update spec helper

  • Loading branch information...
commit 124f0930f28ff8389e93ec8dbc212b860d39dc3f 1 parent fb9970c
Dustin Webber authored
Showing with 12 additions and 11 deletions.
  1. +7 −8 lib/unified2.rb
  2. +4 −2 lib/unified2/event.rb
  3. +1 −1  spec/spec_helper.rb
15 lib/unified2.rb
View
@@ -134,12 +134,12 @@ def self.watch(path, position=:first, &block)
# Start with a null event.
# This will always be ignored.
- @event = Event.new(0)
+ @event = Event.new(0, 0)
loop do
begin
event = Unified2::Constructor::Construct.read(io)
- check_event(event, block)
+ check_event(event, io.pos, block)
rescue EOFError
sleep 5
retry
@@ -175,11 +175,11 @@ def self.read(path, &block)
# Start with a null event.
# This will always be ignored.
- @event = Event.new(0)
+ @event = Event.new(0, 0)
until io.eof?
event = Unified2::Constructor::Construct.read(io)
- check_event(event, block)
+ check_event(event, io.pos, block)
end
rescue Interrupt
@@ -199,15 +199,14 @@ def self.validate_path(path)
end
end
- def self.check_event(event, block)
-
+ def self.check_event(event, position=0, block)
+
if event.data.respond_to?(:event_id)
if @event.id == event.data.event_id
@event.load(event)
else
block.call(@event) unless @event.id.zero?
- @extra_data = false
- @event = Event.new(event.data.event_id)
+ @event = Event.new(event.data.event_id, position.to_i)
@event.load(event)
end
else
6 lib/unified2/event.rb
View
@@ -41,15 +41,16 @@ class Event
#
# Setup method defaults
#
- attr_accessor :id, :event, :packets, :extras
+ attr_accessor :id, :event, :packets, :extras, :position
#
# Initialize event
#
# @param [Integer] id Event id
#
- def initialize(id)
+ def initialize(id, position)
@id = id.to_i
+ @position = position
@packets = []
@extras = []
end
@@ -310,6 +311,7 @@ def load(event)
# @return [Hash] Event hash object
#
def to_h
+ @event_data[:position] = position
@event_data[:protocol] = protocol
@event_data[:timestamp] = timestamp.to_s
@event_data[:checksum] = checksum
2  spec/spec_helper.rb
View
@@ -12,7 +12,7 @@ def self.first(path)
io = File.open(path)
io.sysseek(0, IO::SEEK_SET)
- @event = Event.new(1)
+ @event = Event.new(1, 0)
loop do
event = Unified2::Constructor::Construct.read(io)
Please sign in to comment.
Something went wrong with that request. Please try again.