Class: Peephole::Logline
- Inherits:
-
Object
- Object
- Peephole::Logline
- Defined in:
- app/models/peephole/logline.rb
Defined Under Namespace
Modules: TYPE
Instance Attribute Summary collapse
-
#method ⇒ Object
Returns the value of attribute method.
-
#num ⇒ Object
Returns the value of attribute num.
-
#params ⇒ Object
Returns the value of attribute params.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#status ⇒ Object
Returns the value of attribute status.
-
#target ⇒ Object
Returns the value of attribute target.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
- .each(path, page, &block) ⇒ Object
- .first(page) ⇒ Object
- .last(page) ⇒ Object
- .parse(line, num, loglines, logmap) ⇒ Object
- .where(path, page) ⇒ Object
Instance Method Summary collapse
-
#initialize(line, num) ⇒ Logline
constructor
A new instance of Logline.
Constructor Details
#initialize(line, num) ⇒ Logline
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/peephole/logline.rb', line 63 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
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'app/models/peephole/logline.rb', line 4 def method @method end |
#num ⇒ Object
Returns the value of attribute num.
3 4 5 |
# File 'app/models/peephole/logline.rb', line 3 def num @num end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'app/models/peephole/logline.rb', line 5 def params @params end |
#started_at ⇒ Object
Returns the value of attribute started_at.
4 5 6 |
# File 'app/models/peephole/logline.rb', line 4 def started_at @started_at end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'app/models/peephole/logline.rb', line 6 def status @status end |
#target ⇒ Object
Returns the value of attribute target.
4 5 6 |
# File 'app/models/peephole/logline.rb', line 4 def target @target end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'app/models/peephole/logline.rb', line 3 def type @type end |
#uuid ⇒ Object
Returns the value of attribute uuid.
3 4 5 |
# File 'app/models/peephole/logline.rb', line 3 def uuid @uuid end |
Class Method Details
.each(path, page, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/models/peephole/logline.rb', line 52 def each(path, page, &block) iterator = case path.to_s when /\.gz\z/ Zlib::GzipReader.open(path).each else IO.foreach(path) end iterator.with_index(&block) end |
.first(page) ⇒ Object
15 16 17 |
# File 'app/models/peephole/logline.rb', line 15 def first(page) (page - 1) * Peephole.config.paginates_per end |
.last(page) ⇒ Object
19 20 21 |
# File 'app/models/peephole/logline.rb', line 19 def last(page) page * Peephole.config.paginates_per end |
.parse(line, num, loglines, logmap) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/peephole/logline.rb', line 38 def parse(line, num, loglines, logmap) logline = new(line, num) case logline.type when TYPE::STARTED logmap[logline.uuid] = logline if logline.uuid.present? when TYPE::PARAMS line = logmap[logline.uuid].presence || logline line.params = logline.params loglines << line when TYPE::COMPLETED logmap[logline.uuid].try(:status=, logline.status) end end |
.where(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 where(path, page) loglines = [] logmap = {} eof = true each(path, page) do |line, i| next if i < first(page) if i >= last(page) eof = false break end parse(line, i + 1, loglines, logmap) end [loglines, eof] end |