wolverine 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,18 +4,14 @@ Wolverine is a simple library to allow you to manage and run redis server-side l
4
4
 
5
5
  Redis versions 2.6 and up allow lua scripts to be run on the server that execute atomically and very quickly.
6
6
 
7
- This is *extremely* useful.
8
-
9
7
  Wolverine is a wrapper around that functionality, to package it up in a format more familiar to a Rails codebase.
10
8
 
11
9
  ## How do I use it?
12
10
 
13
- 1) Make sure you have redis 2.6 or higher installed. As of now, that means compiling from source:
11
+ 1) Make sure you have redis 2.6 or higher installed.
14
12
 
15
- ```shell
16
- git clone https://github.com/antirez/redis.git
17
- cd redis && make
18
- ./src/redis-server
13
+ ```
14
+ redis-server -v
19
15
  ```
20
16
 
21
17
  2) Add wolverine to your Gemfile:
@@ -39,7 +35,13 @@ return exists
39
35
  4) Call wolverine from your code:
40
36
 
41
37
  ```ruby
42
- Wolverine.util.mexists('key1', 'key2', 'key3') #=> [0, 1, 0]
38
+ Wolverine.util.mexists(['key1', 'key2', 'key3']) #=> [0, 1, 0]
39
+ ```
40
+
41
+ Or
42
+
43
+ ```ruby
44
+ Wolverine.util.mexists(:keys => ['key1', 'key2', 'key3']) #=> [0, 1, 0]
43
45
  ```
44
46
 
45
47
  Methods are available on `Wolverine` paralleling the directory structure
@@ -59,13 +61,3 @@ If you want to override one or more of these, doing so in an initializer is reco
59
61
 
60
62
  For more information on scripting redis with lua, refer to redis' excellent documentation: http://redis.io/commands/eval
61
63
 
62
- ## License
63
-
64
- Copyright (C) 2012 [Shopify](http://shopify.com) by [Burke Libbey](http://burkelibbey.org)
65
-
66
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
67
-
68
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
69
-
70
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71
-
data/lib/wolverine.rb CHANGED
@@ -30,6 +30,7 @@ class Wolverine
30
30
  # @return [void]
31
31
  def self.reset!
32
32
  @root_directory = nil
33
+ reset_cached_methods
33
34
  end
34
35
 
35
36
  # Used to handle dynamic accesses to scripts. Successful lookups will be
@@ -58,6 +59,7 @@ class Wolverine
58
59
 
59
60
  def reset!
60
61
  @root_directory = nil
62
+ reset_cached_methods
61
63
  end
62
64
 
63
65
  def method_missing sym, *args
@@ -69,11 +71,31 @@ class Wolverine
69
71
  private
70
72
 
71
73
  def self.root_directory
72
- @root_directory ||= PathComponent.new(config.script_path)
74
+ @root_directory ||= PathComponent.new(config.script_path, {:cache_to => self})
75
+ end
76
+
77
+ def self.cached_methods
78
+ @cached_methods ||= Hash.new
79
+ end
80
+
81
+ def self.reset_cached_methods
82
+ metaclass = class << self; self; end
83
+ cached_methods.each_key { |method| metaclass.send(:undef_method, method) }
84
+ cached_methods.clear
73
85
  end
74
86
 
75
87
  def root_directory
76
- @root_directory ||= PathComponent.new(config.script_path, {:config => config, :redis => redis})
88
+ @root_directory ||= PathComponent.new(config.script_path, {:cache_to => self, :config => config, :redis => redis})
89
+ end
90
+
91
+ def cached_methods
92
+ @cached_methods ||= Hash.new
93
+ end
94
+
95
+ def reset_cached_methods
96
+ metaclass = class << self; self; end
97
+ cached_methods.each_key { |method| metaclass.send(:undef_method, method) }
98
+ cached_methods.clear
77
99
  end
78
100
 
79
101
  end
@@ -18,6 +18,7 @@ class Wolverine
18
18
  def initialize path, options = {}
19
19
  @path = path
20
20
  @options = options
21
+ @cache_to = options[:cache_to]
21
22
  @redis = options[:redis] || Wolverine.redis
22
23
  @config = options[:config] || Wolverine.config
23
24
  end
@@ -53,15 +54,19 @@ class Wolverine
53
54
  end
54
55
 
55
56
  def define_directory_method path, sym
56
- dir = PathComponent.new(path, @options)
57
- define_metaclass_method(sym) { dir }
57
+ options = @options.merge({:cache_to => nil})
58
+ dir = PathComponent.new(path, options)
59
+ cb = proc { dir }
60
+ define_metaclass_method(sym, &cb)
61
+ cache_metaclass_method(sym, &cb)
58
62
  end
59
63
 
60
64
  def define_script_method path, sym, *args
61
- script = Wolverine::Script.new(path, @options)
62
- define_metaclass_method(sym) { |*args|
63
- script.call(@redis, *args)
64
- }
65
+ redis, options = @redis, @options.merge({:cache_to => nil})
66
+ script = Wolverine::Script.new(path, options)
67
+ cb = proc { |*args| script.call(redis, *args) }
68
+ define_metaclass_method(sym, &cb)
69
+ cache_metaclass_method(sym, &cb)
65
70
  end
66
71
 
67
72
  def define_metaclass_method sym, &block
@@ -69,6 +74,15 @@ class Wolverine
69
74
  metaclass.send(:define_method, sym, &block)
70
75
  end
71
76
 
77
+ def cache_metaclass_method sym, &block
78
+ unless @cache_to.nil?
79
+ metaclass = class << @cache_to; self; end
80
+ metaclass.send(:define_method, sym, &block)
81
+ cached_methods = @cache_to.send(:cached_methods)
82
+ cached_methods[sym] = self
83
+ end
84
+ end
85
+
72
86
  end
73
87
 
74
88
  end
@@ -47,13 +47,13 @@ class Wolverine
47
47
 
48
48
  def run_evalsha redis, *args
49
49
  instrument :evalsha do
50
- redis.evalsha @digest, args.size, *args
50
+ redis.evalsha @digest, *args
51
51
  end
52
52
  end
53
53
 
54
54
  def run_eval redis, *args
55
55
  instrument :eval do
56
- redis.eval @content, args.size, *args
56
+ redis.eval @content, *args
57
57
  end
58
58
  end
59
59
 
@@ -1,3 +1,3 @@
1
1
  class Wolverine
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -7,10 +7,10 @@ class WolverineIntegrationTest < MiniTest::Unit::TestCase
7
7
  def mock_redis
8
8
  stub.tap do |redis|
9
9
  redis.expects(:evalsha).
10
- with('fe24f4dd4ba7881608cca4b846f009195e06d79a', 2, :a, :b).
10
+ with('fe24f4dd4ba7881608cca4b846f009195e06d79a', :a, :b).
11
11
  raises("NOSCRIPT").once
12
12
  redis.expects(:eval).
13
- with(CONTENT, 2, :a, :b).
13
+ with(CONTENT, :a, :b).
14
14
  returns([1, 0]).once
15
15
  end
16
16
  end
@@ -20,6 +20,7 @@ class WolverineIntegrationTest < MiniTest::Unit::TestCase
20
20
  Wolverine.config.script_path = Pathname.new(File.expand_path('../lua', __FILE__))
21
21
 
22
22
  assert_equal [1, 0], Wolverine.util.mexists(:a, :b)
23
+ assert Wolverine.methods.include?(:util)
23
24
  end
24
25
 
25
26
  def test_everything_instantiated
@@ -28,6 +29,7 @@ class WolverineIntegrationTest < MiniTest::Unit::TestCase
28
29
 
29
30
  wolverine = Wolverine.new(config)
30
31
  assert_equal [1, 0], wolverine.util.mexists(:a, :b)
32
+ assert wolverine.methods.include?(:util)
31
33
  end
32
34
 
33
35
  end
@@ -43,7 +43,7 @@ class Wolverine
43
43
  }
44
44
  Wolverine.config.instrumentation = callback
45
45
  redis = Class.new do
46
- define_method(:evalsha) do |digest, size, *args|
46
+ define_method(:evalsha) do |digest, *args|
47
47
  nil
48
48
  end
49
49
  end
@@ -53,9 +53,8 @@ class Wolverine
53
53
  def test_call_with_cache_hit
54
54
  tc = self
55
55
  redis = Class.new do
56
- define_method(:evalsha) do |digest, size, *args|
56
+ define_method(:evalsha) do |digest, *args|
57
57
  tc.assert_equal DIGEST, digest
58
- tc.assert_equal 2, size
59
58
  tc.assert_equal [:a, :b], args
60
59
  end
61
60
  end
@@ -68,9 +67,8 @@ class Wolverine
68
67
  define_method(:evalsha) do |*|
69
68
  raise "NOSCRIPT No matching script. Please use EVAL."
70
69
  end
71
- define_method(:eval) do |content, size, *args|
70
+ define_method(:eval) do |content, *args|
72
71
  tc.assert_equal CONTENT, content
73
- tc.assert_equal 2, size
74
72
  tc.assert_equal [:a, :b], args
75
73
  end
76
74
  end
data/wolverine.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Wolverine::VERSION
8
8
  s.authors = ["Burke Libbey"]
9
9
  s.email = ["burke@burkelibbey.org"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/Shopify/wolverine"
11
11
  s.summary = %q{Wolverine provides a simple way to run server-side redis scripts from a rails app}
12
12
  s.description = %q{Wolverine provides a simple way to run server-side redis scripts from a rails app}
13
13
 
@@ -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', '>= 2.2.2'
21
+ s.add_runtime_dependency 'redis', '>= 3.0.0'
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,96 +1,96 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wolverine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
5
4
  prerelease:
5
+ version: 0.2.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Burke Libbey
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-05 00:00:00.000000000 Z
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: redis
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
15
+ version_requirements: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
- version: 2.2.2
19
+ version: 3.0.0
20
+ none: false
21
+ name: redis
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
24
+ requirement: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - ! '>='
28
27
  - !ruby/object:Gem::Version
29
- version: 2.2.2
30
- - !ruby/object:Gem::Dependency
31
- name: mocha
32
- requirement: !ruby/object:Gem::Requirement
28
+ version: 3.0.0
33
29
  none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
34
32
  requirements:
35
33
  - - ~>
36
34
  - !ruby/object:Gem::Version
37
35
  version: 0.10.5
36
+ none: false
37
+ name: mocha
38
38
  type: :development
39
39
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
40
+ requirement: !ruby/object:Gem::Requirement
42
41
  requirements:
43
42
  - - ~>
44
43
  - !ruby/object:Gem::Version
45
44
  version: 0.10.5
46
- - !ruby/object:Gem::Dependency
47
- name: minitest
48
- requirement: !ruby/object:Gem::Requirement
49
45
  none: false
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
50
48
  requirements:
51
49
  - - ~>
52
50
  - !ruby/object:Gem::Version
53
51
  version: 2.11.3
52
+ none: false
53
+ name: minitest
54
54
  type: :development
55
55
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
56
+ requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ~>
60
59
  - !ruby/object:Gem::Version
61
60
  version: 2.11.3
62
- - !ruby/object:Gem::Dependency
63
- name: rake
64
- requirement: !ruby/object:Gem::Requirement
65
61
  none: false
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: !ruby/object:Gem::Requirement
66
64
  requirements:
67
65
  - - ! '>='
68
66
  - !ruby/object:Gem::Version
69
67
  version: '0'
68
+ none: false
69
+ name: rake
70
70
  type: :development
71
71
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
72
+ requirement: !ruby/object:Gem::Requirement
74
73
  requirements:
75
74
  - - ! '>='
76
75
  - !ruby/object:Gem::Version
77
76
  version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: yard
80
- requirement: !ruby/object:Gem::Requirement
81
77
  none: false
78
+ - !ruby/object:Gem::Dependency
79
+ version_requirements: !ruby/object:Gem::Requirement
82
80
  requirements:
83
81
  - - ! '>='
84
82
  - !ruby/object:Gem::Version
85
83
  version: '0'
84
+ none: false
85
+ name: yard
86
86
  type: :development
87
87
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
88
+ requirement: !ruby/object:Gem::Requirement
90
89
  requirements:
91
90
  - - ! '>='
92
91
  - !ruby/object:Gem::Version
93
92
  version: '0'
93
+ none: false
94
94
  description: Wolverine provides a simple way to run server-side redis scripts from
95
95
  a rails app
96
96
  email:
@@ -124,24 +124,24 @@ files:
124
124
  - test/wolverine/script_test.rb
125
125
  - test/wolverine_test.rb
126
126
  - wolverine.gemspec
127
- homepage: ''
127
+ homepage: https://github.com/Shopify/wolverine
128
128
  licenses: []
129
129
  post_install_message:
130
130
  rdoc_options: []
131
131
  require_paths:
132
132
  - lib
133
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
- none: false
135
134
  requirements:
136
135
  - - ! '>='
137
136
  - !ruby/object:Gem::Version
138
137
  version: '0'
139
- required_rubygems_version: !ruby/object:Gem::Requirement
140
138
  none: false
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
140
  requirements:
142
141
  - - ! '>='
143
142
  - !ruby/object:Gem::Version
144
143
  version: '0'
144
+ none: false
145
145
  requirements: []
146
146
  rubyforge_project: wolverine
147
147
  rubygems_version: 1.8.23