once 0.0.1 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8172b01a3e28f6aaa417166e71b88c7172596863
4
- data.tar.gz: 0ea53bf46f8db4fde91bccfecc8d070fb8a1df1b
3
+ metadata.gz: bc1dc66aa1467c67d46b20d62737dce0c95dc307
4
+ data.tar.gz: 18db88e365f371eab21b2bca55348e2db40d1f68
5
5
  SHA512:
6
- metadata.gz: 88f0716b9fe70077e28bece1c4225a75becc08d0931ddcc768e12b401ddabcbe9355c24f4ce947c6b3bc86f30a8912ff078d12508b33041ea1a2fcb6caf9b3ce
7
- data.tar.gz: 84235be3a2ad656371f0a430e5f0531ef5d7b9f3c5bec50ce0b93cf7d1fe57443134852635adc1f335bd14c78555d813f399f86254c1d57961e9472747034349
6
+ metadata.gz: 1c3ef2cc6f39da8ee988767b3af06872086ced4f20639d4c356ca7893169e328d73bad675aa3b227ea3993695d8ec90c6351ecd98c65ad695001aab0c5d8e25f
7
+ data.tar.gz: c79340580c1018db34d175055d48170a3300388e03b84c5d205456da408512fbdcc5213ec2512aa39cb61999e609075d28f553aed2920e52b845527298206031
@@ -0,0 +1 @@
1
+ once
@@ -0,0 +1,6 @@
1
+ ## 0.0.3
2
+ * Atomic setex insted of set and expire commands individually
3
+ * Return results of the executed block
4
+
5
+ ## 0.0.1
6
+ * Initial release
@@ -13,7 +13,7 @@ require 'digest'
13
13
  # .. stuff that should happen only once ..
14
14
  # end
15
15
  #
16
- # The combination of the name and params makes the check unique. So typically it would be the
16
+ # The combination of the name and params makes the check unique. So typically it would be the
17
17
  # command you're executing, plus the params to that command
18
18
  module Once
19
19
  DEFAULT_TIME = 3600 # seconds
@@ -37,12 +37,17 @@ module Once
37
37
  hash = Digest::MD5.hexdigest(params.inspect)
38
38
  redis_key = "uniquecheck:#{name}:#{hash}"
39
39
 
40
+ perform(redis_key, &block).tap do
41
+ redis.setex(redis_key, within, true)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def perform(redis_key, &block)
40
48
  unless redis.exists(redis_key)
41
49
  block.call
42
50
  end
43
-
44
- redis.set(redis_key, true)
45
- redis.expire(redis_key, within)
46
51
  end
47
52
  end
48
53
  end
@@ -1,3 +1,3 @@
1
1
  module Once
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -8,7 +8,7 @@ describe Once do
8
8
  Once.redis = Redis.new
9
9
  end
10
10
 
11
- let(:thing_to_execute) { double(execute: nil) }
11
+ let(:thing_to_execute) { double(execute: "foo") }
12
12
  let(:params) {{foo: "bar"}}
13
13
 
14
14
  it "executes the given command" do
@@ -19,6 +19,12 @@ describe Once do
19
19
  thing_to_execute.should have_received(:execute).once
20
20
  end
21
21
 
22
+ it "returns the result of the command" do
23
+ described_class.do(name: "mycheck", params: params) do
24
+ thing_to_execute.execute
25
+ end.should == "foo"
26
+ end
27
+
22
28
  it "executes when called from within different namespaces" do
23
29
  described_class.do(name: "mycheck1", params: params) do
24
30
  thing_to_execute.execute
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: once
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yan Pritzker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-17 00:00:00.000000000 Z
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,7 +88,9 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".ruby-gemset"
91
92
  - ".ruby-version"
93
+ - CHANGELOG.md
92
94
  - Gemfile
93
95
  - LICENSE
94
96
  - README.md