coin 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/coin/vault.rb +18 -7
- data/lib/coin/version.rb +1 -1
- data/test/vault_test.rb +12 -0
- metadata +15 -24
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fea8abcd6b73fc7d8704be672b76bad3ff02d519
|
4
|
+
data.tar.gz: b4ac92e29a08cffb07b6f42329e1d3089429b30e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a5076a10a1d66c65067ba28c8a2ab0027ebb90e8769b1a35773d47429cb8d9861d4f10905aa1db6f94546a5e7596db5f1ccd297f4c984111dd289b629837b31c
|
7
|
+
data.tar.gz: f41bb3710666bd6c1930e388e4b84792c55c3bfd891e3efc391fc4a30e5f8a19151dcef870f27a9e6a82fc8c30f99265feaaa8f5ba8d45dbd34f1bfeef7a7d99
|
data/lib/coin/vault.rb
CHANGED
@@ -17,6 +17,17 @@ module Coin
|
|
17
17
|
nil
|
18
18
|
end
|
19
19
|
|
20
|
+
def write(key, value, lifetime=300)
|
21
|
+
synchronize do
|
22
|
+
@dict[key] = { :value => value, :cached_at => Time.now, :lifetime => lifetime }
|
23
|
+
end
|
24
|
+
value
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(key)
|
28
|
+
synchronize { @dict.delete(key) }
|
29
|
+
end
|
30
|
+
|
20
31
|
def read_and_delete(key)
|
21
32
|
value = nil
|
22
33
|
synchronize do
|
@@ -26,15 +37,15 @@ module Coin
|
|
26
37
|
value
|
27
38
|
end
|
28
39
|
|
29
|
-
def
|
40
|
+
def read_and_write(key, lifetime=300)
|
41
|
+
orig_value = nil
|
42
|
+
value = nil
|
30
43
|
synchronize do
|
31
|
-
|
44
|
+
orig_value = read(key)
|
45
|
+
value = yield(orig_value)
|
46
|
+
write key, value, lifetime
|
32
47
|
end
|
33
|
-
value
|
34
|
-
end
|
35
|
-
|
36
|
-
def delete(key)
|
37
|
-
synchronize { @dict.delete(key) }
|
48
|
+
[orig_value, value]
|
38
49
|
end
|
39
50
|
|
40
51
|
def clear
|
data/lib/coin/version.rb
CHANGED
data/test/vault_test.rb
CHANGED
@@ -26,6 +26,18 @@ class VaultTest < MicroTest::Test
|
|
26
26
|
assert val == value
|
27
27
|
end
|
28
28
|
|
29
|
+
test "read_and_write" do
|
30
|
+
orig_value = rand(999999999)
|
31
|
+
value = nil
|
32
|
+
@vault.write(@key, orig_value)
|
33
|
+
values = @vault.read_and_write(@key) do |val|
|
34
|
+
value = rand(888888888)
|
35
|
+
end
|
36
|
+
assert values.first == orig_value
|
37
|
+
assert values.last == value
|
38
|
+
assert @vault.read(@key) == value
|
39
|
+
end
|
40
|
+
|
29
41
|
test "delete" do
|
30
42
|
@vault.write(@key, true)
|
31
43
|
assert @vault.read(@key)
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nathan Hopkins
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: micro_test
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: pry
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: An absurdly simple in memory object caching system.
|
@@ -67,40 +60,38 @@ executables:
|
|
67
60
|
extensions: []
|
68
61
|
extra_rdoc_files: []
|
69
62
|
files:
|
63
|
+
- bin/coin
|
64
|
+
- lib/coin.rb
|
70
65
|
- lib/coin/vault.rb
|
71
66
|
- lib/coin/version.rb
|
72
|
-
- lib/coin.rb
|
73
|
-
- bin/coin
|
74
67
|
- test/coin_test.rb
|
75
68
|
- test/test_helper.rb
|
76
69
|
- test/vault_test.rb
|
77
70
|
homepage: https://github.com/hopsoft/coin
|
78
71
|
licenses:
|
79
72
|
- MIT
|
73
|
+
metadata: {}
|
80
74
|
post_install_message:
|
81
75
|
rdoc_options: []
|
82
76
|
require_paths:
|
83
77
|
- lib
|
84
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
79
|
requirements:
|
87
|
-
- -
|
80
|
+
- - ">="
|
88
81
|
- !ruby/object:Gem::Version
|
89
82
|
version: '0'
|
90
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
-
none: false
|
92
84
|
requirements:
|
93
|
-
- -
|
85
|
+
- - ">="
|
94
86
|
- !ruby/object:Gem::Version
|
95
87
|
version: '0'
|
96
88
|
requirements: []
|
97
89
|
rubyforge_project:
|
98
|
-
rubygems_version:
|
90
|
+
rubygems_version: 2.2.0
|
99
91
|
signing_key:
|
100
|
-
specification_version:
|
92
|
+
specification_version: 4
|
101
93
|
summary: An absurdly simple in memory object caching system.
|
102
94
|
test_files:
|
103
95
|
- test/coin_test.rb
|
104
96
|
- test/test_helper.rb
|
105
97
|
- test/vault_test.rb
|
106
|
-
has_rdoc:
|