logfile_interval 2.1.2 → 2.1.3

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: 14b39f20fbae9202297e5238d0f5b070ff6e74d3
4
- data.tar.gz: e68b950bb73692646df7e003548294b29c57217a
3
+ metadata.gz: a422a1c2dd8f8e7f23f0383d0e136b092a759bb7
4
+ data.tar.gz: a00233a4c5d418409adebb04192f2ece523afd17
5
5
  SHA512:
6
- metadata.gz: 4854a00f1ffc8a58dc6608c977a0cf6ed89b8affa9b9e81fc271d14f89a0c53edbeb33188255b0eba01893c8fc7c313d09e097a8b1eddc748a56f81efbe21fc4
7
- data.tar.gz: af8d8ba8b2a23cc3d4985763d8f7653c36c1881085107542af2134e5ae4e7488fb345834bd34d06c3406b02671d0e33de2f35b318c60cfac9632e152eaf8f340
6
+ metadata.gz: 10ae89ce0a1634f7cb7f3dd12c9b729cf9b3423a69d6493ec61a185681adbcc5257422c2d9ca02ed353f34d67ec76e244042f1d984dcba0a826c74370f94c9c6
7
+ data.tar.gz: 3795d4971b016b9b5101f387d8fd7ee4dcb9e6551631f100cc7cbb22e49444622826ee8e594102f12fd588f3136f10281379a6f382452bad38f4b6d5b608b3ba
@@ -6,10 +6,13 @@ module LogfileInterval
6
6
 
7
7
  def initialize(filenames, parser, order = :desc, &file_time_finder_block)
8
8
  @parser = parser
9
- @filenames = reject_empty_files(filenames)
9
+ @filenames = filenames
10
10
  @order = order
11
11
  @file_time_finder_block = file_time_finder_block if block_given?
12
12
 
13
+ reject_empty_files!
14
+ reject_files_with_no_valid_line!
15
+
13
16
  raise ArgumentError, "invalid order value: #{@order}" unless ORDER_VALID_VALUES.include?(@order.to_sym)
14
17
  end
15
18
 
@@ -68,10 +71,17 @@ module LogfileInterval
68
71
  end
69
72
  end
70
73
 
71
- def reject_empty_files(filenames)
72
- filenames.reject do |fname|
74
+ def reject_empty_files!
75
+ @filenames.reject do |fname|
73
76
  !File.size?(fname)
74
77
  end
75
78
  end
79
+
80
+ def reject_files_with_no_valid_line!
81
+ @filenames.reject! do |fname|
82
+ file = Logfile.new(fname, parser)
83
+ !file.first_parsed_line
84
+ end
85
+ end
76
86
  end
77
87
  end
@@ -1,3 +1,3 @@
1
1
  module LogfileInterval
2
- VERSION = "2.1.2"
2
+ VERSION = "2.1.3"
3
3
  end
@@ -6,7 +6,8 @@ module LogfileInterval
6
6
 
7
7
  describe LogfileSet do
8
8
  before :each do
9
- @logfiles = ["#{data_dir}/access.log.2", "#{data_dir}/access.log.1", "#{data_dir}/access.log.empty"]
9
+ @logfiles = ["#{data_dir}/access.log.2",
10
+ "#{data_dir}/access.log.1"]
10
11
  @set = LogfileSet.new(@logfiles, ParsedLine::AccessLog)
11
12
  @first_line = '66.249.67.176 - - [23/Jun/2013:17:00:01 -0800] "GET /package/core/raring/universe/proposed/openldap HTTP/1.1" 200 185 "-" "Google"'
12
13
  @second_line = '12.24.48.96 - - [23/Jun/2013:16:59:00 -0800] "GET /package/core/raring/universe/proposed/openldap HTTP/1.1" 200 4555 "-" "Bing)"'
@@ -55,13 +56,6 @@ module LogfileInterval
55
56
  lines.last.should == @first_line
56
57
  end
57
58
  end
58
-
59
- context 'emoty logfiles' do
60
- it 'are ignored' do
61
- set = LogfileSet.new(@logfiles, ParsedLine::AccessLog, :asc)
62
- expect(set.ordered_filenames).to_not include("#{data_dir}/access.log.empty")
63
- end
64
- end
65
59
  end
66
60
 
67
61
  describe :each_parsed_line do
@@ -95,6 +89,32 @@ module LogfileInterval
95
89
  @set.ordered_filenames.should == @non_empty_logfiles.reverse
96
90
  end
97
91
 
92
+ context 'empty logfiles' do
93
+ before :each do
94
+ logfiles = ["#{data_dir}/access.log.2",
95
+ "#{data_dir}/access.log.1",
96
+ "#{data_dir}/access.log.empty"]
97
+ @set_with_empty = LogfileSet.new(logfiles, ParsedLine::AccessLog)
98
+ end
99
+
100
+ it 'are ignored' do
101
+ expect(@set_with_empty.ordered_filenames).to_not include("#{data_dir}/access.log.empty")
102
+ end
103
+ end
104
+
105
+ context 'logfiles with no valid line' do
106
+ before :each do
107
+ logfiles = ["#{data_dir}/access.log.2",
108
+ "#{data_dir}/access.log.1",
109
+ "#{data_dir}/access.log.invalid"]
110
+ @set_with_invalid = LogfileSet.new(logfiles, ParsedLine::AccessLog)
111
+ end
112
+
113
+ it 'are ignored' do
114
+ expect(@set_with_invalid.ordered_filenames).to_not include("#{data_dir}/access.log.invalid")
115
+ end
116
+ end
117
+
98
118
  context 'with file_time_finder_block' do
99
119
  it 'sorts the files in the order described in the block' do
100
120
  set = LogfileSet.new(@logfiles, ParsedLine::AccessLog) do |filename|
@@ -0,0 +1 @@
1
+ no valid line
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logfile_interval
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Le Rohellec
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-12 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,6 +137,7 @@ files:
137
137
  - spec/support/logfiles/access.log.2
138
138
  - spec/support/logfiles/access.log.3
139
139
  - spec/support/logfiles/access.log.empty
140
+ - spec/support/logfiles/access.log.invalid
140
141
  - spec/support/logfiles/timing.log
141
142
  - spec/support/logfiles/timing.log.1
142
143
  - spec/support/logfiles/timing.log.2
@@ -183,6 +184,7 @@ test_files:
183
184
  - spec/support/logfiles/access.log.2
184
185
  - spec/support/logfiles/access.log.3
185
186
  - spec/support/logfiles/access.log.empty
187
+ - spec/support/logfiles/access.log.invalid
186
188
  - spec/support/logfiles/timing.log
187
189
  - spec/support/logfiles/timing.log.1
188
190
  - spec/support/logfiles/timing.log.2