simple_stats_store 1.0.4 → 1.0.5

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: 11f8d3e8e99a6bef9199f16be06b9abb82d21e78
4
- data.tar.gz: d5379b72cfc958607572ea809ffc43448724204e
3
+ metadata.gz: 87cd10bcfb5223a8e802b5c681546d6705615e51
4
+ data.tar.gz: 9657435d113c733d6e19749f20cc12aa95338769
5
5
  SHA512:
6
- metadata.gz: f7de803ffcc617d5711870cb4499702b8344b1dddcc904a522ee590232300b566836cf1718b584d1c4a9f61ac301abfab14d274b25f3c020defaaba98d086553
7
- data.tar.gz: ad7830d2f1d8b75f276cd82d3e6793994ee7ba77ed8194ea7009e72e4c0988622fcc962dd050b280e03de35a267a19f548daf8fe9e6dc8f6423ca2d686f0e812
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
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-24 00:00:00.000000000 Z
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