myslog 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/myslog.rb +11 -11
  2. data/myslog.gemspec +1 -1
  3. data/spec/myslog.rb +4 -2
  4. metadata +3 -3
data/lib/myslog.rb CHANGED
@@ -18,8 +18,8 @@
18
18
  require "time"
19
19
 
20
20
  class MySlog
21
- def parse(lines)
22
- divide(lines).map {|record| parse_record(record) }
21
+ def parse(text)
22
+ divide(text.split("\n")).map {|r| parse_record(r) }
23
23
  end
24
24
 
25
25
  def divide(lines)
@@ -51,32 +51,32 @@ class MySlog
51
51
  records
52
52
  end
53
53
 
54
- def parse_record(lines)
54
+ def parse_record(records)
55
55
  response = {}
56
56
 
57
- line = lines.shift
58
- if line.start_with? "# Time:"
59
- date = line[8..-1].strip
57
+ record = records.shift
58
+ if record.start_with? "# Time:"
59
+ date = record[8..-1].strip
60
60
  response[:date] = Time.parse(date)
61
61
 
62
- line = lines.shift
62
+ record = records.shift
63
63
  else
64
64
  response[:date] = nil
65
65
  end
66
66
 
67
- elems = line.split(" ")
67
+ elems = record.split(" ")
68
68
  response[:user] = elems[2].strip
69
69
  response[:host] = elems[4].strip
70
70
  response[:host_ip] = elems[5].strip[1...-1]
71
71
 
72
- line = lines.shift
73
- elems = line.split(" ")
72
+ record = records.shift
73
+ elems = record.split(" ")
74
74
  response[:query_time] = elems[2].to_f
75
75
  response[:lock_time] = elems[4].to_f
76
76
  response[:rows_sent] = elems[6].to_i
77
77
  response[:rows_examined] = elems[8].to_i
78
78
 
79
- response[:sql] = lines.map{|line| line.strip}.join("\n")
79
+ response[:sql] = records.shift
80
80
 
81
81
  response
82
82
  end
data/myslog.gemspec CHANGED
@@ -12,6 +12,6 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "myslog"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "0.0.3"
15
+ gem.version = "0.0.4"
16
16
  gem.add_development_dependency "rspec"
17
17
  end
data/spec/myslog.rb CHANGED
@@ -46,12 +46,11 @@ use webtie;
46
46
 
47
47
  before :each do
48
48
  @myslog = MySlog.new
49
- @lines = @log.split("\n").map {|line| line.chomp}
50
49
  end
51
50
 
52
51
  describe "#parse" do
53
52
  it "should return Array of Hash" do
54
- results = @myslog.parse(@lines)
53
+ results = @myslog.parse(@log)
55
54
  results.should be_an_instance_of Array
56
55
  results.each do |result|
57
56
  results.should be_an_instance_of Array
@@ -60,6 +59,9 @@ use webtie;
60
59
  end
61
60
 
62
61
  describe "#divide" do
62
+ before :each do
63
+ @lines = @log.split("\n").map {|line| line.chomp}
64
+ end
63
65
 
64
66
  it "should return Array of Array" do
65
67
  results = @myslog.divide(@lines)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myslog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70298330581000 !ruby/object:Gem::Requirement
16
+ requirement: &70181126520020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70298330581000
24
+ version_requirements: *70181126520020
25
25
  description: MySQL slow query parser.
26
26
  email:
27
27
  - taka84u9@gmail.com