fake_go_up 0.2.1 → 0.2.2

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: 8abfd9b0f85dd9abf41d8027f25307a97ebd294f
4
- data.tar.gz: f35e2d685e67d2b205ca3b72c73cc5f523d34504
3
+ metadata.gz: 98e032f39b7d3eb4958b2de9dc91c44441ee73af
4
+ data.tar.gz: 25d61e1a017b9db5da6143c85d497f0baca1c2b1
5
5
  SHA512:
6
- metadata.gz: 8a2edb9edbf3defef8f41a8979306a708a1ae88928632a9e3d6fc0907e1d5925013cd985d218d329d3e9dd23bf702ce3bf5585cd549a5968eaeb9b5fbc0017f9
7
- data.tar.gz: e999f3460f3fee43400f7d522c59b6c978795ae37d8b9ce20f73589769b9425103a633980990739b90c76bcb205a8675085942c5e3e9afba10167f447ba52d8b
6
+ metadata.gz: 2025e0d97da18cb3bff3ba4707403bf3f4a3be38caa63e42da19b8bf5124f29668cf8e7dff0a5a71370344628efba2e12ea9b8465d873ce12bac9bd552642d0c
7
+ data.tar.gz: 9e81a61e9c9ec12a5edb0509278b2e529ad59620a76fbcb7ea2563f741f6791e569fefd436c8538bafab749be0516c99bd2c61b6077ec7f7d868ff089c8f85a4
@@ -1,26 +1,45 @@
1
1
  module FakeGoUp
2
2
  class Item
3
- attr_accessor :count
4
-
5
- @@data = {}
3
+ attr_reader :count
4
+ REDIS_KEY = "fake_go_up:items"
5
+ @@instance_collector = {}
6
6
 
7
7
  def initialize(id = 1)
8
8
  @id = id
9
9
  @count = 0
10
+ @@instance_collector[id] = self
10
11
  end
11
12
 
12
13
  def id
13
14
  @id
14
15
  end
15
16
 
17
+ def count= (c)
18
+ FakeGoUp.redis.hset(FakeGoUp::Item::REDIS_KEY, id, c)
19
+ @count = c
20
+ end
21
+
16
22
  def self.find_by_id(id)
17
- @@data[id.to_i]
23
+ id = id.to_i
24
+
25
+ instance = self.instances[id]
26
+ return instance if instance
27
+
28
+ count = FakeGoUp.redis.hget(FakeGoUp::Item::REDIS_KEY, id).to_i
29
+ instance = self.new(id)
30
+ instance.count = count
31
+ instance
18
32
  end
19
33
 
20
34
  def self.create(id)
21
- instance = new(id)
22
- @@data[id] = instance
23
- instance
35
+ id = id.to_i
36
+
37
+ FakeGoUp.redis.hset(FakeGoUp::Item::REDIS_KEY, id, 0)
38
+ new(id)
39
+ end
40
+
41
+ def self.instances
42
+ @@instance_collector
24
43
  end
25
44
  end
26
- end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module FakeGoUp
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_go_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - xuxiangyang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pid_lock