exedb 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/exedb/version.rb +1 -1
  3. data/lib/exedb.rb +19 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b260ba9f2075f0a3e24dc3329578b8198d75110b
4
- data.tar.gz: aea82d16176964d1f1907e39815d2ad4223b1035
3
+ metadata.gz: b90d8a0eccdf874db978cd3490ff651214838103
4
+ data.tar.gz: 48d5871d5cc81292a24b946878949dc69ac21037
5
5
  SHA512:
6
- metadata.gz: 74036155baa5670c00ed225ca1299b810fe7c6002801ca1113d5c94adfa4d99566d33d8d08b353d933e36cda8d0e84a118c44b1b55addd4eae2eefca6ea4bea9
7
- data.tar.gz: ffa382688d4d13d854fcfaa9e5adc622cbfe5e65229aa336924cc3f87ad64b38c5f3229525c84c0a4a97802ba4406fab22b55a16f8ae348ea7f01248a4df1260
6
+ metadata.gz: ecafa6e021bf8974b3e8c2dc9327a4d08b742c018ce269728a452c19ebe9478776fce2088771fc438a76075525ed8e80eb9a701a59c9c76879a31eb350c55a9a
7
+ data.tar.gz: ea42ddfbebadf99450215d2eb085edca4afff791c3f8482e848f3e7d5768d2e60c2ebc885abb806079c50724a3b970d87554f9e00c8bb31c659eaa9c43e8d07b
data/lib/exedb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Exedb
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/exedb.rb CHANGED
@@ -42,7 +42,13 @@ class Exedb
42
42
  # will be started
43
43
  def update
44
44
  @content=''
45
- File.open(@path, File::RDWR|File::CREAT, 0644) { |file|
45
+
46
+ # create file if needed
47
+ unless File.file?(@path)
48
+ File.open(@path,File::RDWR|File::CREAT,0644){|f|}
49
+ end
50
+
51
+ File.open(@path, "r+:UTF-8") { |file|
46
52
  if file.flock(File::LOCK_EX|File::LOCK_NB)
47
53
  begin
48
54
  IO.popen(@update_method){|pipe|
@@ -58,20 +64,22 @@ class Exedb
58
64
  end
59
65
  }
60
66
  @code=$?.exitstatus
61
- #warn "UPDATED: #{@content}/#{@code}"
62
67
  rescue
63
68
  @content=''
64
69
  @code=-1
65
70
  end
66
- @content=@alltransform.call(@content,@code) if @alltransform
67
- file.write @content
68
- file.flush
71
+ if @alltransform
72
+ @content=@alltransform.call(@content,@code)
73
+ file.seek(0,IO::SEEK_SET)
74
+ file.write @content
75
+ file.truncate(@content.size)
76
+ file.flush
77
+ end
69
78
  File.open("#{@path}.code",File::RDWR|File::CREAT, 0644){|code_file|
70
79
  code_file.puts @code
71
80
  }
72
81
  file.flock(File::LOCK_UN)
73
82
  else
74
- warn "CANNOT LOCK"
75
83
  read_cache
76
84
  end
77
85
  @update_time=Time.now
@@ -206,13 +214,17 @@ protected
206
214
  end
207
215
 
208
216
  def generate_key u
209
- return Digest::SHA256.hexdigest u
217
+ f=u.tr('^qwertyuiopasdfghjklzxcvbnm_-','')
218
+ d=Digest::SHA256.hexdigest(u)
219
+ return f[0,60]+'..'+f[-60,60]+d if f.size>128
220
+ return f+d
210
221
  end
211
222
 
212
223
  def read_cache
213
224
  File.open(@path, File::RDONLY) { |file|
214
225
  file.flock(File::LOCK_EX)
215
226
  @content=file.read
227
+ warn "CACHE READ: #{@content}"
216
228
  File.open("#{@path}.code", File::RDONLY) { |code_file|
217
229
  c=code_file.gets
218
230
  c =~ /([0-9-]+)/
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exedb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Zhumatiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-07 00:00:00.000000000 Z
11
+ date: 2014-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler