simple_stats_store 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/simple_stats_store/file_dump.rb +13 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87cd10bcfb5223a8e802b5c681546d6705615e51
|
4
|
+
data.tar.gz: 9657435d113c733d6e19749f20cc12aa95338769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9d3a228e875866a192a754b30104a957d5c9d96fb7877ea7c86aa80e9102b6a42d23a99495ae120a3178e9a5ef9a4adc423d24618023f6c2ccfa378b061c7f3
|
7
|
+
data.tar.gz: 66a0fce20c27dd58e173a22b78e9bd091fbbe057c4879ac72ce76a9218f848136cbadeffaf9c7d25b8869a8d2aa7ba9f49bdad55454f614abd5a1e9ecc920213
|
@@ -2,8 +2,9 @@ require 'tempfile'
|
|
2
2
|
|
3
3
|
module SimpleStatsStore
|
4
4
|
class FileDump
|
5
|
-
def initialize(dir)
|
5
|
+
def initialize(dir, options = {})
|
6
6
|
@dir = dir
|
7
|
+
@max = options.has_key?(:max) ? options[:max] : nil
|
7
8
|
end
|
8
9
|
|
9
10
|
def files_contents
|
@@ -28,14 +29,23 @@ module SimpleStatsStore
|
|
28
29
|
|
29
30
|
def write(model, data)
|
30
31
|
i = 0
|
31
|
-
subdir = File.expand_path(model, @dir)
|
32
|
+
subdir = File.expand_path(model.to_s, @dir)
|
32
33
|
Dir.mkdir(subdir) if ! Dir.exists?(subdir)
|
34
|
+
if ! @max.nil?
|
35
|
+
files = Dir["#{subdir}/*"].sort { |a, b| File.ctime(a) <=> File.ctime(b) }
|
36
|
+
if files.length >= @max
|
37
|
+
files[0..(@max-files.length)].each do |f|
|
38
|
+
File.delete(f)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
33
43
|
while File.exists?(File.expand_path("sss-#{$$}-#{Time.new.to_i}-#{i}.stats", subdir))
|
34
44
|
i += 1
|
35
45
|
end
|
36
46
|
File.open(File.expand_path("sss-#{$$}-#{Time.new.to_i}-#{i}.stats", subdir), 'w') do |f|
|
37
47
|
f.puts "---"
|
38
|
-
f.puts model
|
48
|
+
f.puts model.to_s
|
39
49
|
data.each do |key, value|
|
40
50
|
f.puts "#{key.to_s}: #{value}"
|
41
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_stats_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Haig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Using SQLite3 to store statistics from a multithreaded application
|
14
14
|
email: joe.haig@bbc.co.uk
|