wolverine 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -6
- data/README.md +1 -1
- data/lib/wolverine.rb +1 -1
- data/lib/wolverine/lua_error.rb +22 -3
- data/lib/wolverine/path_component.rb +2 -2
- data/lib/wolverine/script.rb +1 -1
- data/lib/wolverine/version.rb +1 -1
- data/test/wolverine/script_test.rb +23 -5
- data/test/wolverine_test.rb +3 -3
- metadata +4 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c99e5c41a4cefcc95117a816b79749347384c113
|
4
|
+
data.tar.gz: 6e5f1372a5dee252622f964edc15ca38bd24d20f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6afecaf7f571d80b536344babb0e4cc60829ff310885e728a09bf4e017f3065cc78a1e1a9fbc2b564338446b163b50be40fd910eea05217f3676a2f20955119d
|
7
|
+
data.tar.gz: 26169bdd7b1e5f9c5c464248950afca91e59772011a92142e8fb5a259b63dfa53cee69c69ac9672581422b2a684bb1f1ba99970e5d96582c979dfd4f9d38796d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Wolverine [![Dependency Status](https://gemnasium.com/Shopify/wolverine.png)](https://gemnasium.com/Shopify/wolverine)
|
1
|
+
# Wolverine [![Dependency Status](https://gemnasium.com/Shopify/wolverine.png)](https://gemnasium.com/Shopify/wolverine) [![Build Status](https://travis-ci.org/Shopify/wolverine.svg?branch=master)](https://travis-ci.org/Shopify/wolverine)
|
2
2
|
|
3
3
|
Wolverine is a simple library to allow you to manage and run redis server-side lua scripts from a rails app, or other ruby code.
|
4
4
|
|
data/lib/wolverine.rb
CHANGED
data/lib/wolverine/lua_error.rb
CHANGED
@@ -7,6 +7,9 @@ class Wolverine
|
|
7
7
|
class LuaError < StandardError
|
8
8
|
PATTERN = /ERR Error (compiling|running) script \(.*?\): .*?:(\d+): (.*)/
|
9
9
|
WOLVERINE_LIB_PATH = File.expand_path('../../', __FILE__)
|
10
|
+
CONTEXT_LINE_NUMBER = 2
|
11
|
+
|
12
|
+
attr_reader :error, :file, :content
|
10
13
|
|
11
14
|
# Is this error one that should be reformatted?
|
12
15
|
#
|
@@ -21,19 +24,35 @@ class Wolverine
|
|
21
24
|
#
|
22
25
|
# @param error [StandardError] the original error raised by redis
|
23
26
|
# @param file [Pathname] full path to the lua file the error ocurred in
|
24
|
-
|
27
|
+
# @param content [String] lua file content the error ocurred in
|
28
|
+
def initialize error, file, content
|
25
29
|
@error = error
|
26
30
|
@file = file
|
31
|
+
@content = content
|
27
32
|
|
28
33
|
@error.message =~ PATTERN
|
29
|
-
|
34
|
+
_stage, line_number, message = $1, $2, $3
|
35
|
+
error_context = generate_error_context(content, line_number.to_i)
|
30
36
|
|
31
|
-
super message
|
37
|
+
super "#{message}\n\n#{error_context}\n\n"
|
32
38
|
set_backtrace generate_backtrace file, line_number
|
33
39
|
end
|
34
40
|
|
35
41
|
private
|
36
42
|
|
43
|
+
def generate_error_context(content, line_number)
|
44
|
+
lines = content.lines.to_a
|
45
|
+
beginning_line_number = [1, line_number - CONTEXT_LINE_NUMBER].max
|
46
|
+
ending_line_number = [lines.count, line_number + CONTEXT_LINE_NUMBER].min
|
47
|
+
line_number_width = ending_line_number.to_s.length
|
48
|
+
|
49
|
+
(beginning_line_number..ending_line_number).map do |number|
|
50
|
+
indicator = number == line_number ? '=>' : ' '
|
51
|
+
formatted_number = "%#{line_number_width}d" % number
|
52
|
+
" #{indicator} #{formatted_number}: #{lines[number - 1]}"
|
53
|
+
end.join.chomp
|
54
|
+
end
|
55
|
+
|
37
56
|
def generate_backtrace(file, line_number)
|
38
57
|
pre_wolverine = backtrace_before_entering_wolverine(@error.backtrace)
|
39
58
|
index_of_first_wolverine_line = (@error.backtrace.size - pre_wolverine.size - 1)
|
@@ -50,7 +50,7 @@ class Wolverine
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def file?(path)
|
53
|
-
File.
|
53
|
+
File.exist?(path) && !File.directory?(path)
|
54
54
|
end
|
55
55
|
|
56
56
|
def define_directory_method path, sym
|
@@ -64,7 +64,7 @@ class Wolverine
|
|
64
64
|
def define_script_method path, sym, *args
|
65
65
|
redis, options = @redis, @options.merge({:cache_to => nil})
|
66
66
|
script = Wolverine::Script.new(path, options)
|
67
|
-
cb = proc { |*
|
67
|
+
cb = proc { |*cb_args| script.call(redis, *cb_args) }
|
68
68
|
define_metaclass_method(sym, &cb)
|
69
69
|
cache_metaclass_method(sym, &cb)
|
70
70
|
end
|
data/lib/wolverine/script.rb
CHANGED
data/lib/wolverine/version.rb
CHANGED
@@ -3,7 +3,16 @@ require 'digest/sha1'
|
|
3
3
|
|
4
4
|
class Wolverine
|
5
5
|
class ScriptTest < MiniTest::Unit::TestCase
|
6
|
-
CONTENT =
|
6
|
+
CONTENT = <<EOC
|
7
|
+
local key, score, member, context, max_rank = KEYS[1], ARGV[1], ARGV[2], ARGV[3], ARGV[4]
|
8
|
+
redis.call('ZADD', key, score, member)
|
9
|
+
|
10
|
+
local rank = redis.call('ZRANK', key, member)
|
11
|
+
if rank > max_rank then
|
12
|
+
return {}
|
13
|
+
end
|
14
|
+
return redis.call('ZRANGE', start, end, 'WITHSCORES')
|
15
|
+
EOC
|
7
16
|
DIGEST = Digest::SHA1.hexdigest(CONTENT)
|
8
17
|
|
9
18
|
def setup
|
@@ -22,13 +31,22 @@ class Wolverine
|
|
22
31
|
|
23
32
|
def test_error
|
24
33
|
redis = stub
|
25
|
-
redis.expects(:evalsha).raises(%q{ERR Error running script (call to f_178d75adaa46af3d8237cfd067c9fdff7b9d504f): [string "func definition"]:
|
34
|
+
redis.expects(:evalsha).raises(%q{ERR Error running script (call to f_178d75adaa46af3d8237cfd067c9fdff7b9d504f): [string "func definition"]:5: attempt to compare nil with number})
|
26
35
|
begin
|
27
36
|
script.call(redis)
|
28
37
|
rescue Wolverine::LuaError => e
|
29
|
-
assert_equal
|
30
|
-
|
31
|
-
|
38
|
+
assert_equal <<EOS, e.message
|
39
|
+
attempt to compare nil with number
|
40
|
+
|
41
|
+
3:
|
42
|
+
4: local rank = redis.call('ZRANK', key, member)
|
43
|
+
=> 5: if rank > max_rank then
|
44
|
+
6: return {}
|
45
|
+
7: end
|
46
|
+
|
47
|
+
EOS
|
48
|
+
assert_equal "/a/b/c/d/e/file1.lua:5", e.backtrace.first
|
49
|
+
assert_match(/script.rb/, e.backtrace[1])
|
32
50
|
end
|
33
51
|
end
|
34
52
|
|
data/test/wolverine_test.rb
CHANGED
@@ -8,10 +8,10 @@ class WolverineTest < MiniTest::Unit::TestCase
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_reset!
|
11
|
-
dir = Wolverine.root_directory
|
12
|
-
assert_equal Wolverine.root_directory, dir
|
11
|
+
dir = Wolverine.send(:root_directory)
|
12
|
+
assert_equal Wolverine.send(:root_directory), dir
|
13
13
|
Wolverine.reset!
|
14
|
-
refute_equal Wolverine.root_directory, dir
|
14
|
+
refute_equal Wolverine.send(:root_directory), dir
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_instantiate_wolverine_with_config
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wolverine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burke Libbey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -136,19 +136,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project: wolverine
|
139
|
-
rubygems_version: 2.6.
|
139
|
+
rubygems_version: 2.6.14
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Wolverine provides a simple way to run server-side redis scripts from a rails
|
143
143
|
app
|
144
|
-
test_files:
|
145
|
-
- test/integration/lua/util/mexists.lua
|
146
|
-
- test/integration/wolverine_integration_test.rb
|
147
|
-
- test/test_helper.rb
|
148
|
-
- test/wolverine/configuration_test.rb
|
149
|
-
- test/wolverine/lua/outer.lua
|
150
|
-
- test/wolverine/lua/shared/_inner.lua
|
151
|
-
- test/wolverine/path_component_test.rb
|
152
|
-
- test/wolverine/script_templating_test.rb
|
153
|
-
- test/wolverine/script_test.rb
|
154
|
-
- test/wolverine_test.rb
|
144
|
+
test_files: []
|