rack-logs 0.0.2 → 0.0.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: 69a6f50b97b494a90f92e1add5f1035070664cd8
4
- data.tar.gz: 3c43793be423daa785e0a2fba594eaa6bfad8f95
3
+ metadata.gz: e0a1cdc66577d3ba82418770cc9ca462b3f81581
4
+ data.tar.gz: a9c6ce4f050fac22cff08d242acb0e1c553b3173
5
5
  SHA512:
6
- metadata.gz: 863295e75ba0b0e61800fb7d1bb79ddc69cd50030c43b8ebed78a2ce44e72f37fc8b2e65e328746ca3f9a43410107910af03508d9a0061e46e9025f34432f193
7
- data.tar.gz: a091fa3ed21370358b59e1da7f22209e7d0689463c33c731cdb69e511904acd6379e4658259629884e9cc4eba7b87fed3ee51ddcf29f5876503bf420ac7b9e9f
6
+ metadata.gz: a3a948077177fc75c6bda202e718d534331637175f6ab55395b68a6835d2f2fa393c2a20f93ed167bb296411692d6f8479d381fda172eb418f40949786e7bc98
7
+ data.tar.gz: e373503195bfcb176e4039c416f38f308604c771d32197d0805624cd9b386c6793d27ab2a1849e76224950b60eaf0b6383f13072d17423b595c59fc691220173
@@ -5,9 +5,10 @@ module Rack
5
5
  def initialize
6
6
  @pattern = '*.log'
7
7
  @log_dir = './log'
8
+ @lines = 200
8
9
  end
9
10
 
10
- attr_accessor :pattern, :log_dir
11
+ attr_accessor :pattern, :log_dir, :lines
11
12
 
12
13
  end
13
14
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Logs
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -20,22 +20,34 @@ module Rack
20
20
  end
21
21
 
22
22
  class JoinedFiles
23
- def initialize filenames
23
+ include Enumerable
24
+
25
+ def initialize filenames, lines
24
26
  @filenames = filenames
27
+ @lines = lines
25
28
  end
26
29
 
27
30
  def each &block
28
31
  @filenames.each do |filename|
29
32
  block.call "## #{filename}\n\n"
30
33
  ::File.open(filename) do |file|
31
- file.each(&block)
34
+ total = 0
35
+ file.each_line { total += 1 }
36
+ progress = 0
37
+ file.rewind
38
+ file.each_line do |line|
39
+ if progress > (total - @lines)
40
+ block.call line
41
+ end
42
+ progress += 1
43
+ end
32
44
  end
33
45
  end
34
46
  end
35
47
  end
36
48
 
37
49
  def joined_logs
38
- JoinedFiles.new files
50
+ JoinedFiles.new files, @config.lines
39
51
  end
40
52
 
41
53
  def logs
@@ -22,4 +22,14 @@ describe 'Rack::Logs::Config' do
22
22
  expect(config.pattern).to eq '*.doge'
23
23
  end
24
24
  end
25
+
26
+ describe '#lines' do
27
+ it 'defaults to 200' do
28
+ expect(config.lines).to eq 200
29
+ end
30
+ it 'is configurable' do
31
+ config.lines = 300
32
+ expect(config.lines).to eq 300
33
+ end
34
+ end
25
35
  end
@@ -2,7 +2,7 @@ require 'fakefs/safe'
2
2
  require 'rack/logs/viewer'
3
3
 
4
4
  describe 'Rack::Logs::Viewer' do
5
- let(:config) { instance_double "Rack::Logs::Config", pattern: '*.doge', log_dir: './tmp' }
5
+ let(:config) { instance_double "Rack::Logs::Config", pattern: '*.doge', log_dir: './tmp', lines: 5 }
6
6
 
7
7
  describe '#initialize' do
8
8
  it 'takes a configuration' do
@@ -13,12 +13,19 @@ describe 'Rack::Logs::Viewer' do
13
13
  describe '#call env' do
14
14
  let(:viewer) { Rack::Logs::Viewer.new config }
15
15
  let(:response) { viewer.call({}) }
16
+ let(:contents) { response[2].inject("") { |contents, fragment| contents + fragment } }
16
17
 
17
18
  before do
18
19
  FakeFS.activate!
19
20
  FileUtils.mkdir_p('./tmp')
20
21
  File.open('./tmp/not_log.txt','w') { |file| file.write 'Nothing to see here' }
21
- File.open('./tmp/my_log.doge','w') { |file| file.write 'Much log, such information' }
22
+ File.open('./tmp/my_log.doge','w') do |file|
23
+ file.write "Ignored"
24
+ 4.times do
25
+ file.write $/
26
+ end
27
+ file.write "Much log, such information"
28
+ end
22
29
  end
23
30
  after do
24
31
  FakeFS.deactivate!
@@ -31,11 +38,11 @@ describe 'Rack::Logs::Viewer' do
31
38
  expect(response[2].respond_to? :each).to be true
32
39
  end
33
40
  it 'returns the contents of the logs' do
34
- contents = ""
35
- response[2].each do |fragment|
36
- contents << fragment
37
- end
38
- expect(contents).to eq "## tmp/my_log.doge\n\nMuch log, such information"
41
+ expect(contents).to match "## tmp/my_log\.doge\n\n"
42
+ expect(contents).to match "Much log, such information"
43
+ end
44
+ it 'limits itself to the last n lines' do
45
+ expect(contents).to_not match "Ignored"
39
46
  end
40
47
  end
41
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Rowe