Class: Peephole::Logline

Inherits:
Object
  • Object
show all
Defined in:
app/models/peephole/logline.rb

Defined Under Namespace

Modules: TYPE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, num) ⇒ Logline

Returns a new instance of Logline.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/peephole/logline.rb', line 91

def initialize(line, num)
  self.num = num

  case line
  when / Started (\w+) "(.+)" .+ at (.+)/
    self.method = $1
    self.target = $2
    self.started_at = Time.parse($3)
    self.type = TYPE::STARTED
  when /   Parameters: ({.+})/
    params = JSON.parse($1.gsub('=>', ':'))
    params.dup.each do |k, v|
      if v.is_a?(Hash)
        v.each do |k2, v2|
          params["#{k}[#{k2}]"] = v2
        end
        params.delete(k)
      end
    end
    self.params = params
    self.type = TYPE::PARAMS
  when / Completed (\d+)/
    self.status = $1
    self.type = TYPE::COMPLETED
  end
  if line =~ /\[(\w+\-\w+\-\w+\-\w+\-\w+)\] /
    self.uuid = $1
  end
end

Instance Attribute Details

#methodObject

Returns the value of attribute method.



4
5
6
# File 'app/models/peephole/logline.rb', line 4

def method
  @method
end

#numObject

Returns the value of attribute num.



3
4
5
# File 'app/models/peephole/logline.rb', line 3

def num
  @num
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'app/models/peephole/logline.rb', line 5

def params
  @params
end

#started_atObject

Returns the value of attribute started_at.



4
5
6
# File 'app/models/peephole/logline.rb', line 4

def started_at
  @started_at
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'app/models/peephole/logline.rb', line 6

def status
  @status
end

#targetObject

Returns the value of attribute target.



4
5
6
# File 'app/models/peephole/logline.rb', line 4

def target
  @target
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'app/models/peephole/logline.rb', line 3

def type
  @type
end

#uuidObject

Returns the value of attribute uuid.



3
4
5
# File 'app/models/peephole/logline.rb', line 3

def uuid
  @uuid
end

Class Method Details

.bytes(path, page) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'app/models/peephole/logline.rb', line 46

def bytes(path, page)
  eof = false
  raw = ''
  open(path) do |f|
    f.seek(first_byte(page))
    raw = f.read(Peephole.config.bytes_per)
    eof = f.eof?
  end
  [raw, eof]
end

.first_byte(page) ⇒ Object



38
39
40
# File 'app/models/peephole/logline.rb', line 38

def first_byte(page)
  first(page, :byte)
end

.first_line(page) ⇒ Object



15
16
17
# File 'app/models/peephole/logline.rb', line 15

def first_line(page)
  first(page, :line)
end

.last_byte(page) ⇒ Object



42
43
44
# File 'app/models/peephole/logline.rb', line 42

def last_byte(page)
  last(page, :byte)
end

.last_line(page) ⇒ Object



19
20
21
# File 'app/models/peephole/logline.rb', line 19

def last_line(page)
  last(page, :line)
end

.lines(path, page) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/peephole/logline.rb', line 23

def lines(path, page)
  lines = []
  map = {}
  eof = true
  each(path, page) do |line, i|
    next if i < first_line(page)
    if i >= last_line(page)
      eof = false
      break
    end
    parse(line, i + 1, lines, map)
  end
  [lines, eof]
end