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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf4207f40c547957cd25192cd7d340436621215e
4
- data.tar.gz: 313dc90cebe900a51b469f5ce486331f830ebbf9
3
+ metadata.gz: c99e5c41a4cefcc95117a816b79749347384c113
4
+ data.tar.gz: 6e5f1372a5dee252622f964edc15ca38bd24d20f
5
5
  SHA512:
6
- metadata.gz: 518af0757e2192af3b6c93378fbb1ac9b6e7ed6fca3fa2d08f441bc9cd9b68b8f40b199fa6b49884bbb476dfc1e580b3554e107296c1b80df00f7e562d419795
7
- data.tar.gz: f5b866107a41eafb8c265dbea9280000d7041fc0b298c2ee8bd0e22202bc7825b588811dc5bf306befe9a9651ef1269f61d26744e2e50131e192beca7baaba4d
6
+ metadata.gz: 6afecaf7f571d80b536344babb0e4cc60829ff310885e728a09bf4e017f3065cc78a1e1a9fbc2b564338446b163b50be40fd910eea05217f3676a2f20955119d
7
+ data.tar.gz: 26169bdd7b1e5f9c5c464248950afca91e59772011a92142e8fb5a259b63dfa53cee69c69ac9672581422b2a684bb1f1ba99970e5d96582c979dfd4f9d38796d
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
3
  - 1.9.3
6
- - jruby-18mode
4
+ - 2.0.0
5
+ - 2.1.10
6
+ - 2.2.7
7
+ - 2.3.4
8
+ - 2.4.1
9
+ - ruby-head
7
10
  - jruby-19mode
8
- - rbx-18mode
9
- - rbx-19mode
10
-
11
+ - jruby-9.1.9.0
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
 
@@ -24,7 +24,7 @@ class Wolverine
24
24
  end
25
25
 
26
26
  def self.statsd_enabled?
27
- @statsd_enabled
27
+ defined?(@statsd_enabled) && @statsd_enabled
28
28
  end
29
29
 
30
30
  def self.enable_statsd!
@@ -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
- def initialize error, file
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
- stage, line_number, message = $1, $2, $3
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.exists?(path) && !File.directory?(path)
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 { |*args| script.call(redis, *args) }
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
@@ -39,7 +39,7 @@ class Wolverine
39
39
  end
40
40
  rescue => e
41
41
  if LuaError.intercepts?(e)
42
- raise LuaError.new(e, @file)
42
+ raise LuaError.new(e, @file, @content)
43
43
  else
44
44
  raise
45
45
  end
@@ -1,3 +1,3 @@
1
1
  class Wolverine
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -3,7 +3,16 @@ require 'digest/sha1'
3
3
 
4
4
  class Wolverine
5
5
  class ScriptTest < MiniTest::Unit::TestCase
6
- CONTENT = "return 1"
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"]:1: attempt to compare nil with number})
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 "attempt to compare nil with number", e.message
30
- assert_equal "/a/b/c/d/e/file1.lua:1", e.backtrace.first
31
- assert_match /script.rb/, e.backtrace[1]
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
 
@@ -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
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: 2017-06-23 00:00:00.000000000 Z
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.10
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: []