file_series 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/VERSION +1 -1
- data/file_series.gemspec +5 -3
- data/lib/file_series.rb +17 -0
- data/spec/file_series_spec.rb +23 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzFjMWYwOWRjM2JmYWI2ZjY4ZDJkNTVhODE3Y2YwMGJkNTAxODM3Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmFmYTNhYzczMGUwMzAzNGYzZWE4MDhiMTJhNmJiZDA5NjNlYzNjNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Njc2MGY4NmEzOWRjMGNiYTc0MjA1NTJiOTAxOWYwMGI0YWIxODZjNDgxOTQ4
|
10
|
+
MTVhZTgyMzcxMTI2ODRkMmIyZTJiMjI2OGRmNmIwNmYyMjlhYmQwMTk2Mzcx
|
11
|
+
ZWMxZTRmNmRlYzE1NzA2ZDk2NjRkZWQwOTU5NzVmMjY3MTBiYzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWEwMmY4OWNmNTZlOTI2ZjE1NGNjZTlmYzc2MjQ3MWEyYmQ2MDYxNmM3ODgx
|
14
|
+
M2QwYTM5ZjU2ZWRiOWEzMDU0MTU0Mzc5NDk0ZGY5MjViNTAyMGZhMDc4N2Jh
|
15
|
+
MzU3NWY1MTRhNmFkMWY4ZmQ1NTVmZDhiNTRiMzdhZGUwMWM5NmU=
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
file_series
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p194
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/file_series.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: file_series 0.
|
5
|
+
# stub: file_series 0.6.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "file_series"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.6.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Alex Dean"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2015-01-05"
|
15
15
|
s.description = "Automatically start writing to a new file every X seconds without any locking or file moving/renaming."
|
16
16
|
s.email = "alex@crackpot.org"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
".autotest",
|
23
23
|
".document",
|
24
24
|
".rspec",
|
25
|
+
".ruby-gemset",
|
26
|
+
".ruby-version",
|
25
27
|
"Gemfile",
|
26
28
|
"Gemfile.lock",
|
27
29
|
"LICENSE.txt",
|
data/lib/file_series.rb
CHANGED
@@ -75,11 +75,28 @@ class FileSeries
|
|
75
75
|
|
76
76
|
# return a string filename for the logfile for the supplied timestamp.
|
77
77
|
# defaults to current time period.
|
78
|
+
#
|
79
|
+
# changes to filename structure must be matched by changes to parse_filename
|
78
80
|
def filename(ts=nil)
|
79
81
|
ts ||= this_period
|
80
82
|
File.join(@dir, "#{@filename_prefix}-#{Time.at(ts).utc.strftime('%Y%m%d-%H%M%SZ')}-#{@rotate_freq}.log")
|
81
83
|
end
|
82
84
|
|
85
|
+
# extract the parts of a filename
|
86
|
+
def self.parse_filename(filename)
|
87
|
+
base = File.basename(filename, '.log')
|
88
|
+
prefix, date, time, duration = base.split('-')
|
89
|
+
{
|
90
|
+
prefix: prefix,
|
91
|
+
start_time: Time.parse("#{date} #{time}").utc,
|
92
|
+
duration: duration.to_i
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_filename(filename)
|
97
|
+
self.class.parse_filename(filename)
|
98
|
+
end
|
99
|
+
|
83
100
|
def path
|
84
101
|
filename
|
85
102
|
end
|
data/spec/file_series_spec.rb
CHANGED
@@ -102,17 +102,38 @@ describe "FileSeries" do
|
|
102
102
|
|
103
103
|
describe "#filename" do
|
104
104
|
it "should accept a timestamp argument" do
|
105
|
-
fs = FileSeries.new(
|
105
|
+
fs = FileSeries.new(:dir=>'/tmp', :prefix=>'test', :rotate_every=>60)
|
106
106
|
fs.filename(Time.parse('1970-01-01 00:20:34Z').to_i).should eq "/tmp/test-19700101-002034Z-60.log"
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should use this_period when no timestamp is supplied" do
|
110
|
-
fs = FileSeries.new(
|
110
|
+
fs = FileSeries.new(:dir=>'/tmp', :prefix=>'test', :rotate_every=>3600)
|
111
111
|
fs.should_receive(:this_period) { Time.parse('1970-01-01 00:20:00Z').to_i }
|
112
112
|
fs.filename.should == "/tmp/test-19700101-002000Z-3600.log"
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
+
describe "parse_filename" do
|
117
|
+
it "should return a hash of information about a filename" do
|
118
|
+
data = FileSeries.parse_filename("/tmp/test-19700101-002000Z-3600.log")
|
119
|
+
|
120
|
+
data[:prefix].should eq 'test'
|
121
|
+
data[:start_time].should eq Time.parse('1970-01-01T00:20:00Z')
|
122
|
+
data[:duration].should eq 3600
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should have an instance version also" do
|
126
|
+
filename = "/tmp/test-19700101-002000Z-3600.log"
|
127
|
+
data1 = FileSeries.parse_filename(filename)
|
128
|
+
|
129
|
+
fs = FileSeries.new(:dir=>'/tmp', :prefix=>'test', :rotate_every=>3600)
|
130
|
+
data2 = fs.parse_filename(filename)
|
131
|
+
|
132
|
+
data2.should eq data1
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
116
137
|
describe "#path" do
|
117
138
|
it "should act like #filename with no arguments" do
|
118
139
|
fs = FileSeries.new( :dir=>'/tmp', :prefix=>'test', :rotate_every=>3600)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_series
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dean
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -92,6 +92,8 @@ files:
|
|
92
92
|
- .autotest
|
93
93
|
- .document
|
94
94
|
- .rspec
|
95
|
+
- .ruby-gemset
|
96
|
+
- .ruby-version
|
95
97
|
- Gemfile
|
96
98
|
- Gemfile.lock
|
97
99
|
- LICENSE.txt
|