wolverine 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wolverine.rb +27 -1
- data/lib/wolverine/configuration.rb +1 -1
- data/lib/wolverine/lua_error.rb +2 -2
- data/lib/wolverine/path_component.rb +9 -5
- data/lib/wolverine/script.rb +5 -4
- data/lib/wolverine/version.rb +2 -2
- data/test/integration/wolverine_integration_test.rb +10 -2
- data/test/wolverine/configuration_test.rb +1 -1
- data/test/wolverine/path_component_test.rb +1 -1
- data/test/wolverine/script_test.rb +1 -1
- data/test/wolverine_test.rb +10 -0
- data/wolverine.gemspec +1 -1
- metadata +39 -15
data/lib/wolverine.rb
CHANGED
@@ -7,7 +7,7 @@ require 'wolverine/script'
|
|
7
7
|
require 'wolverine/path_component'
|
8
8
|
require 'wolverine/lua_error'
|
9
9
|
|
10
|
-
|
10
|
+
class Wolverine
|
11
11
|
# Returns the configuration object for reading and writing
|
12
12
|
# configuration values.
|
13
13
|
#
|
@@ -44,10 +44,36 @@ module Wolverine
|
|
44
44
|
super
|
45
45
|
end
|
46
46
|
|
47
|
+
def initialize(config = nil)
|
48
|
+
@config = config
|
49
|
+
end
|
50
|
+
|
51
|
+
def config
|
52
|
+
@config || self.class.config
|
53
|
+
end
|
54
|
+
|
55
|
+
def redis
|
56
|
+
config.redis
|
57
|
+
end
|
58
|
+
|
59
|
+
def reset!
|
60
|
+
@root_directory = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def method_missing sym, *args
|
64
|
+
root_directory.send(sym, *args)
|
65
|
+
rescue PathComponent::MissingTemplate
|
66
|
+
super
|
67
|
+
end
|
68
|
+
|
47
69
|
private
|
48
70
|
|
49
71
|
def self.root_directory
|
50
72
|
@root_directory ||= PathComponent.new(config.script_path)
|
51
73
|
end
|
52
74
|
|
75
|
+
def root_directory
|
76
|
+
@root_directory ||= PathComponent.new(config.script_path, {:config => config, :redis => redis})
|
77
|
+
end
|
78
|
+
|
53
79
|
end
|
data/lib/wolverine/lua_error.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
class Wolverine
|
2
2
|
# Reformats errors raised by redis representing failures while executing
|
3
3
|
# a lua script. The default errors have confusing messages and backtraces,
|
4
4
|
# and a type of +RuntimeError+. This class improves the message and
|
5
5
|
# modifies the backtrace to include the lua script itself in a reasonable
|
6
6
|
# way.
|
7
7
|
class LuaError < StandardError
|
8
|
-
PATTERN = /ERR Error (compiling|running) script \(.*?\):
|
8
|
+
PATTERN = /ERR Error (compiling|running) script \(.*?\): .*?:(\d+): (.*)/
|
9
9
|
WOLVERINE_LIB_PATH = File.expand_path('../../', __FILE__)
|
10
10
|
|
11
11
|
# Is this error one that should be reformatted?
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
class Wolverine
|
2
2
|
# A {PathComponent} represents either the +Wolverine.config.script_path+
|
3
3
|
# directory, or a subdirectory of it. Calling (nearly) any method on it will
|
4
4
|
# cause it to look in the filesystem at the location it refers to for a file
|
@@ -14,8 +14,12 @@ module Wolverine
|
|
14
14
|
class MissingTemplate < StandardError ; end
|
15
15
|
|
16
16
|
# @param path [Pathname] full path to the current file or directory
|
17
|
-
|
17
|
+
# @param redis [Redis]
|
18
|
+
def initialize path, options = {}
|
18
19
|
@path = path
|
20
|
+
@options = options
|
21
|
+
@redis = options[:redis] || Wolverine.redis
|
22
|
+
@config = options[:config] || Wolverine.config
|
19
23
|
end
|
20
24
|
|
21
25
|
# @param sym [Symbol] the file or directory to look up and execute
|
@@ -49,14 +53,14 @@ module Wolverine
|
|
49
53
|
end
|
50
54
|
|
51
55
|
def define_directory_method path, sym
|
52
|
-
dir = PathComponent.new(path)
|
56
|
+
dir = PathComponent.new(path, @options)
|
53
57
|
define_metaclass_method(sym) { dir }
|
54
58
|
end
|
55
59
|
|
56
60
|
def define_script_method path, sym, *args
|
57
|
-
script = Wolverine::Script.new(path)
|
61
|
+
script = Wolverine::Script.new(path, @options)
|
58
62
|
define_metaclass_method(sym) { |*args|
|
59
|
-
script.call(
|
63
|
+
script.call(@redis, *args)
|
60
64
|
}
|
61
65
|
end
|
62
66
|
|
data/lib/wolverine/script.rb
CHANGED
@@ -2,7 +2,7 @@ require 'pathname'
|
|
2
2
|
require 'benchmark'
|
3
3
|
require 'digest/sha1'
|
4
4
|
|
5
|
-
|
5
|
+
class Wolverine
|
6
6
|
# {Script} represents a lua script in the filesystem. It loads the script
|
7
7
|
# from disk and handles talking to redis to execute it. Error handling
|
8
8
|
# is handled by {LuaError}.
|
@@ -11,10 +11,11 @@ module Wolverine
|
|
11
11
|
# Loads the script file from disk and calculates its +SHA1+ sum.
|
12
12
|
#
|
13
13
|
# @param file [Pathname] the full path to the indicated file
|
14
|
-
def initialize file
|
14
|
+
def initialize file, options = {}
|
15
15
|
@file = Pathname.new(file)
|
16
16
|
@content = load_lua file
|
17
17
|
@digest = Digest::SHA1.hexdigest @content
|
18
|
+
@config = options[:config] || Wolverine.config
|
18
19
|
end
|
19
20
|
|
20
21
|
# Passes the script and supplied arguments to redis for evaulation.
|
@@ -59,12 +60,12 @@ module Wolverine
|
|
59
60
|
def instrument eval_type
|
60
61
|
ret = nil
|
61
62
|
runtime = Benchmark.realtime { ret = yield }
|
62
|
-
|
63
|
+
@config.instrumentation.call relative_path.to_s, runtime, eval_type
|
63
64
|
ret
|
64
65
|
end
|
65
66
|
|
66
67
|
def relative_path
|
67
|
-
path
|
68
|
+
@path ||= @file.relative_path_from(@config.script_path)
|
68
69
|
end
|
69
70
|
|
70
71
|
def load_lua file
|
data/lib/wolverine/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.2.
|
1
|
+
class Wolverine
|
2
|
+
VERSION = "0.2.5"
|
3
3
|
end
|
@@ -8,10 +8,10 @@ class WolverineIntegrationTest < MiniTest::Unit::TestCase
|
|
8
8
|
stub.tap do |redis|
|
9
9
|
redis.expects(:evalsha).
|
10
10
|
with('fe24f4dd4ba7881608cca4b846f009195e06d79a', 2, :a, :b).
|
11
|
-
raises("NOSCRIPT")
|
11
|
+
raises("NOSCRIPT").once
|
12
12
|
redis.expects(:eval).
|
13
13
|
with(CONTENT, 2, :a, :b).
|
14
|
-
returns([1, 0])
|
14
|
+
returns([1, 0]).once
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -22,4 +22,12 @@ class WolverineIntegrationTest < MiniTest::Unit::TestCase
|
|
22
22
|
assert_equal [1, 0], Wolverine.util.mexists(:a, :b)
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_everything_instantiated
|
26
|
+
script_path = Pathname.new(File.expand_path('../lua', __FILE__))
|
27
|
+
config = Wolverine::Configuration.new(mock_redis, script_path)
|
28
|
+
|
29
|
+
wolverine = Wolverine.new(config)
|
30
|
+
assert_equal [1, 0], wolverine.util.mexists(:a, :b)
|
31
|
+
end
|
32
|
+
|
25
33
|
end
|
data/test/wolverine_test.rb
CHANGED
@@ -14,4 +14,14 @@ class WolverineTest < MiniTest::Unit::TestCase
|
|
14
14
|
refute_equal Wolverine.root_directory, dir
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_instantiate_wolverine_with_config
|
18
|
+
r = Struct.new(:Redis)
|
19
|
+
config = Wolverine::Configuration.new(r, 'path')
|
20
|
+
wolverine = Wolverine.new(config)
|
21
|
+
|
22
|
+
assert_equal r, wolverine.config.redis
|
23
|
+
assert_equal r, wolverine.redis
|
24
|
+
assert_equal 'path', wolverine.config.script_path
|
25
|
+
end
|
26
|
+
|
17
27
|
end
|
data/wolverine.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_runtime_dependency 'redis', '
|
21
|
+
s.add_runtime_dependency 'redis', '>= 2.2.2'
|
22
22
|
s.add_development_dependency 'mocha', '~> 0.10.5'
|
23
23
|
s.add_development_dependency 'minitest', '~> 2.11.3'
|
24
24
|
s.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wolverine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,27 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 2.2.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.2.2
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: mocha
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 0.10.5
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.10.5
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: minitest
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 2.11.3
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.11.3
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rake
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: yard
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,7 +85,12 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
description: Wolverine provides a simple way to run server-side redis scripts from
|
70
95
|
a rails app
|
71
96
|
email:
|
@@ -119,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
144
|
version: '0'
|
120
145
|
requirements: []
|
121
146
|
rubyforge_project: wolverine
|
122
|
-
rubygems_version: 1.8.
|
147
|
+
rubygems_version: 1.8.23
|
123
148
|
signing_key:
|
124
149
|
specification_version: 3
|
125
150
|
summary: Wolverine provides a simple way to run server-side redis scripts from a rails
|
@@ -132,4 +157,3 @@ test_files:
|
|
132
157
|
- test/wolverine/path_component_test.rb
|
133
158
|
- test/wolverine/script_test.rb
|
134
159
|
- test/wolverine_test.rb
|
135
|
-
has_rdoc:
|