log_parser 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb1f9e6441835510f872d57775b0a110af39da64
4
- data.tar.gz: f66ab92bb2d953afd409289012f6ab55996f8192
3
+ metadata.gz: 36142163ba2daa7fc0c5696d61ace414bf990c53
4
+ data.tar.gz: 7221c22e2e25cf8f7ecf108e0bf69a546440ab85
5
5
  SHA512:
6
- metadata.gz: 28f051e09df01a61e4030debadd7ccdff952a3e7e5db684f9edb92d0fd8959c96d8d9ca4daa7bb56905ffa0c1156d65ae1e61b76fd34a43afea918f378cbc4aa
7
- data.tar.gz: 66e4fab78c195b9f1fe2622b1059e0ddc1da9b78f6d8dec9fce3b678cb1a30697fcf2f5ed2516550e720d372b76d99c11aabf65bfb028d26a4164524a6e6c164
6
+ metadata.gz: 0718a695404977a316621a6528859f0ae0359418097bbfa6dd1de2f87a2841961221024efe1dc742aeb064279f492ff10e9744eefeea1be32568c2b0971763b3
7
+ data.tar.gz: 18017b6591cfcc422d34a3f52a067adbfcb2d0ec636cf2cb5e58dafc91a194a3d2a19ad74e431e65717ab13e49c8d21df5042cab4d9b9ae298a0765cec3722f3
data/Rakefile CHANGED
@@ -1,9 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rake'
3
3
  require 'rake/testtask'
4
4
 
5
- task default: :test
6
-
7
5
  Rake::TestTask.new do |t|
8
6
  t.pattern = 'test/**/*_test.rb'
9
7
  end
8
+
9
+ desc 'Run tests'
10
+ task default: :test
@@ -28,7 +28,7 @@ module LogParser
28
28
  #
29
29
  def initialize(log = '', options = {})
30
30
  @file = log.is_a?(String) ? LogParser.path_for(log) : log
31
- @lines = options.fetch :line_items, []
31
+ @lines = options.fetch :line_items, nil
32
32
  @pattern = options.fetch :pattern, LINE_PATTERN
33
33
  end
34
34
 
@@ -110,6 +110,8 @@ module LogParser
110
110
  lines.count
111
111
  end
112
112
 
113
+ alias length count
114
+
113
115
  def sort
114
116
  lines.sort
115
117
  end
@@ -147,7 +149,7 @@ module LogParser
147
149
  end
148
150
 
149
151
  def lines
150
- @lines = scan if @lines.nil? || @lines.empty?
152
+ @lines = scan if @lines.nil?
151
153
  @lines
152
154
  end
153
155
 
@@ -1,3 +1,3 @@
1
1
  module LogParser
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
data/lib/log_parser.rb CHANGED
@@ -1,13 +1,11 @@
1
+ require 'date'
2
+
1
3
  require 'log_parser/version'
2
4
  require 'log_parser/line_item'
3
5
  require 'log_parser/client'
4
6
 
5
7
  module LogParser
6
- def self.root
7
- File.expand_path('../..', __FILE__)
8
- end
9
-
10
8
  def self.path_for(file)
11
- Pathname.new(File.join(root, 'log', file))
9
+ Pathname.new(File.join(Dir.pwd, 'log', file))
12
10
  end
13
11
  end
@@ -0,0 +1,8 @@
1
+ [2014-11-13T23:12:10-07:00] INFO: [page_id 24323] Updating page and reviews
2
+ [2014-11-13T23:12:12-07:00] INFO: [page_id 24323] Reviews found
3
+ ¯\_(ツ)_/¯ I don't know h0w I got here
4
+ [2014-11-13T23:12:14-07:00] INFO: [page_id 24323] Saved 10 reviews
5
+ [2014-11-13T23:12:15-07:00] WARNING: [page_id 75645] Failed to find page (maybe it doesn't exists?)
6
+ [2014-11-13T23:12:16-15:00] INFO: [page_id 95239] Updating page and reviews
7
+ [2014-11-13T23:12:17-07:00] INFO: [page_id 95239] Reviews found
8
+ [2014-11-13T23:12:18-07:00] ERROR: [page_id 95239] Failed to save reviews! Validation failed: Text can't be blank
@@ -4,10 +4,66 @@ require 'log_parser'
4
4
 
5
5
  class LogParser::ClientTest < MiniTest::Unit::TestCase
6
6
 
7
+ def setup
8
+ @file = Pathname.new(File.join(Dir.pwd, 'test', 'fixtures', 'example.log'))
9
+ @log = LogParser::Client.new(@file)
10
+ end
11
+
7
12
  def test_initialize_with_string
8
- @log = LogParser::Client.new('production.log')
9
- assert_kind_of Pathname, @log.file_path
10
- assert_equal '/log', @log.file_path.to_s
13
+ @log = LogParser::Client.new('test.log')
14
+ assert_kind_of Pathname, @log.file
15
+ assert_match %r{/log_parser/log/test.log}, @log.file.to_s
11
16
  end
12
17
 
18
+ def test_initialize_with_pathname
19
+ assert_kind_of Pathname, @log.file
20
+ assert_equal @log.file.to_s, @file.to_s
21
+ assert_equal File.exists?(@log.file), true
22
+ end
23
+
24
+ def test_errors
25
+ errors = @log.errors.to_a
26
+ assert_equal 1, errors.count
27
+ assert_equal 'page_id 95239', errors.first.prefix
28
+ assert_match /failed to save/i, errors.first.message
29
+ end
30
+
31
+ def test_warnings
32
+ warnings = @log.warnings.to_a
33
+ assert_equal 1, warnings.count
34
+ assert_equal 'page_id 75645', warnings.first.prefix
35
+ assert_match /failed to find page/i, warnings.first.message
36
+ end
37
+
38
+ def test_infos
39
+ infos = @log.infos.to_a
40
+ assert_equal 5, infos.count
41
+ assert_equal 'page_id 24323', infos.first.prefix
42
+ assert_match /Updating page/i, infos.first.message
43
+ end
44
+
45
+ def test_since
46
+ lines = @log.since(DateTime.parse('2014-11-13T23:12:15-07:00')).to_a
47
+ assert_equal 3, lines.count
48
+ assert_equal '[page_id 95239] Updating page and reviews', lines.first.full_message
49
+ end
50
+
51
+ def test_by_message
52
+ lines = @log.by_message('validation failed').to_a
53
+ assert_equal 1, lines.count
54
+ assert_equal %Q([2014-11-13T23:12:18-07:00] ERROR: [page_id 95239] Failed to save reviews! Validation failed: Text can't be blank),
55
+ lines.first.to_s
56
+ end
57
+
58
+ def test_by_prefix
59
+ lines = @log.by_prefix('page_id 24323').to_a
60
+ assert_equal 3, lines.count
61
+ assert_equal ['page_id 24323'], lines.map(&:prefix).uniq
62
+ end
63
+
64
+ def test_prefixes
65
+ prefixes = @log.prefixes
66
+ assert_equal 3, prefixes.count
67
+ assert_equal ['page_id 24323', 'page_id 75645', 'page_id 95239'], prefixes
68
+ end
13
69
  end
@@ -4,7 +4,6 @@ require 'log_parser/line_item'
4
4
  class LineItemTest < MiniTest::Unit::TestCase
5
5
 
6
6
  def test_full_message
7
- assert_equal '', ''
8
7
  end
9
8
 
10
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-15 00:00:00.000000000 Z
11
+ date: 2014-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,6 +55,7 @@ files:
55
55
  - lib/log_parser/line_item.rb
56
56
  - lib/log_parser/version.rb
57
57
  - log_parser.gemspec
58
+ - test/fixtures/example.log
58
59
  - test/log_parser/client_test.rb
59
60
  - test/log_parser/line_item_test.rb
60
61
  homepage: https://github.com/ridiculous
@@ -82,5 +83,6 @@ signing_key:
82
83
  specification_version: 4
83
84
  summary: Easily search log files
84
85
  test_files:
86
+ - test/fixtures/example.log
85
87
  - test/log_parser/client_test.rb
86
88
  - test/log_parser/line_item_test.rb