shapkeep 0.0.1 → 0.1.0
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 +4 -4
- data/README.md +4 -0
- data/lib/shapkeep.rb +14 -6
- data/lib/shapkeep/version.rb +1 -1
- data/spec/fixtures/return_two.lua +1 -0
- data/spec/fixtures/store.yml +2 -0
- data/spec/shapkeep_spec.rb +8 -3
- metadata +4 -3
- data/sha_file.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea90acf8097d5ef116cc325be6d7abb35fcaf52d
|
4
|
+
data.tar.gz: 1171724f33cfd62b827532305e39cb56a156245c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5209adce06728a4383b1d438b3ddd57b3dc784531f64582e830c01f098a76548dcebe316ce9c8184877539827a3c0cc45e12ee3ed53a7b7ad9d8dae31a17d1e
|
7
|
+
data.tar.gz: 2cf976a9b348c96283211bef1939ce5a9e502d8a7e9a0cbba4cfebc6aad4a98ce82b4ab385a13c419082657457a06ccedd384506db193058e2e50da471bd9ec8
|
data/README.md
CHANGED
data/lib/shapkeep.rb
CHANGED
@@ -13,7 +13,7 @@ class Shapkeep
|
|
13
13
|
def eval(redis, name, keys = [], args = [])
|
14
14
|
begin
|
15
15
|
invalid_script_name!(name) unless script_available?(name)
|
16
|
-
redis.evalsha(
|
16
|
+
redis.evalsha(sha_for_script_name(name), keys, args)
|
17
17
|
rescue Redis::CommandError => boom
|
18
18
|
raise boom unless boom.message.include?('NOSCRIPT')
|
19
19
|
|
@@ -36,16 +36,24 @@ class Shapkeep
|
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
-
def
|
40
|
-
script_store[name.to_sym][:sha] ||=
|
39
|
+
def sha_for_script_name(name)
|
40
|
+
script_store[name.to_sym][:sha] ||= script_sha(script_for_name(name))
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
Digest::SHA1.hexdigest(
|
43
|
+
def script_sha(script)
|
44
|
+
Digest::SHA1.hexdigest(script)
|
45
45
|
end
|
46
46
|
|
47
47
|
def script_for_name(name)
|
48
|
-
script_store[name.to_sym][:script]
|
48
|
+
potential_script = script_store[name.to_sym][:script]
|
49
|
+
|
50
|
+
return potential_script unless lua_filename?(potential_script)
|
51
|
+
|
52
|
+
File.read(potential_script)
|
53
|
+
end
|
54
|
+
|
55
|
+
def lua_filename?(string)
|
56
|
+
['.lua', '.LUA'].include?(string[-4..-1])
|
49
57
|
end
|
50
58
|
|
51
59
|
def load_script(redis, name)
|
data/lib/shapkeep/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
return 2
|
data/spec/fixtures/store.yml
CHANGED
data/spec/shapkeep_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Shapkeep do
|
|
5
5
|
subject { Shapkeep.new('spec/fixtures/store.yml') }
|
6
6
|
|
7
7
|
context 'script store' do
|
8
|
-
specify { expect(subject.script_store.keys).to eq([:zero, :one]) }
|
8
|
+
specify { expect(subject.script_store.keys).to eq([:zero, :one, :file]) }
|
9
9
|
end
|
10
10
|
|
11
11
|
context 'script available' do
|
@@ -16,8 +16,8 @@ describe Shapkeep do
|
|
16
16
|
describe 'load scripts' do
|
17
17
|
before { redis.script(:flush); subject.load_scripts!(redis) }
|
18
18
|
specify do
|
19
|
-
expect(redis.script(:exists, [subject.send(:
|
20
|
-
subject.send(:
|
19
|
+
expect(redis.script(:exists, [subject.send(:sha_for_script_name, :zero),
|
20
|
+
subject.send(:sha_for_script_name, :one)])).to be_true
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -46,6 +46,11 @@ describe Shapkeep do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
context 'script is filename' do
|
50
|
+
before { redis.script(:flush) }
|
51
|
+
specify { expect(subject.eval(redis, :file)).to eq(2) }
|
52
|
+
end
|
53
|
+
|
49
54
|
context 'script errors' do
|
50
55
|
subject { Shapkeep.new('spec/fixtures/store_error.yml') }
|
51
56
|
specify do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shapkeep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- j-wilkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -82,8 +82,8 @@ files:
|
|
82
82
|
- lib/shapkeep.rb
|
83
83
|
- lib/shapkeep/version.rb
|
84
84
|
- lib/shapkeep/wrapper.rb
|
85
|
-
- sha_file.yml
|
86
85
|
- shapkeep.gemspec
|
86
|
+
- spec/fixtures/return_two.lua
|
87
87
|
- spec/fixtures/store.yml
|
88
88
|
- spec/fixtures/store_error.yml
|
89
89
|
- spec/shapkeep/wrapper_spec.rb
|
@@ -114,6 +114,7 @@ signing_key:
|
|
114
114
|
specification_version: 4
|
115
115
|
summary: EVAL Lua scripts in Redis by name
|
116
116
|
test_files:
|
117
|
+
- spec/fixtures/return_two.lua
|
117
118
|
- spec/fixtures/store.yml
|
118
119
|
- spec/fixtures/store_error.yml
|
119
120
|
- spec/shapkeep/wrapper_spec.rb
|