remix-stash 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -16,12 +16,6 @@ Right now remix-stash is designed to be run as a gem. I've published it to both
16
16
 
17
17
  gem install remix-stash --source=http://gemcutter.org/
18
18
 
19
- ## Install via GitHub
20
-
21
- Warning: THIS IS CURRENTLY LIMITED TO VERSION 0.9.6 (until github reenables gem building).
22
-
23
- gem install binary42-remix-stash --source=http://gems.github.com/
24
-
25
19
  # Using Remix::Stash
26
20
 
27
21
  The examples directory has some simple code snippets that introduce general features of the library. In general, everything should just work after `require 'remix/stash'`. This includes integration with Rails and automatic pick-up of Heroku style memcached environment variables. Of course, this library is completely independent of Rails and does not need environment variables to function or be used.
data/Rakefile CHANGED
@@ -14,3 +14,4 @@ begin
14
14
  rescue LoadError
15
15
  puts 'Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com'
16
16
  end
17
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.1.0
@@ -0,0 +1,43 @@
1
+ require 'remix/stash'
2
+
3
+ module ActiveSupport
4
+ module Cache
5
+ class RemixStashStore < Store
6
+
7
+ def initialize(*servers)
8
+ if servers.last.is_a?(Hash)
9
+ # were passing extra settings
10
+ stash.default(servers.pop)
11
+ end
12
+ Remix::Stash.define_cluster(:environment => servers)
13
+ stash.default(:cluster => :environment)
14
+ @stash = Remix::Stash.new(:active_support_cache)
15
+ end
16
+
17
+ def read(name, options = nil)
18
+ super
19
+ @stash[name]
20
+ end
21
+
22
+ def write(name, value, options = nil)
23
+ super
24
+ @stash[name] = value.freeze
25
+ end
26
+
27
+ def delete(name, options = nil)
28
+ super
29
+ @stash.clear(name)
30
+ end
31
+
32
+ def exist?(name, options = nil)
33
+ super
34
+ @stash.read(name)
35
+ end
36
+
37
+ def clear
38
+ @stash.clear
39
+ end
40
+
41
+ end
42
+ end
43
+ end
data/lib/remix/stash.rb CHANGED
@@ -278,7 +278,7 @@ private
278
278
 
279
279
  def load_value(data)
280
280
  Marshal.load(data) if data
281
- rescue TypeError, ArgumentError => e
281
+ rescue TypeError, NameError, ArgumentError => e
282
282
  if e.message =~ /undefined class\/module (.*)/
283
283
  retry if begin
284
284
  $1.split('::').inject(Object) {|m,x|
@@ -317,7 +317,9 @@ private
317
317
 
318
318
  end
319
319
 
320
- class Object; include Remix::Stash::Extension end
321
- module Remix; extend Remix::Stash::Extension end
320
+ module Remix
321
+ extend Remix::Stash::Extension
322
+ include Remix::Stash::Extension
323
+ end
322
324
 
323
325
  require 'remix/stash/auto_detection'
@@ -1,4 +1,6 @@
1
1
  if defined?(Rails)
2
+ require 'active_support/cache/remix_stash_store'
3
+
2
4
  Remix::Stash::Runtime.logger = Rails.logger
3
5
 
4
6
  module Remix::Stash::RailsSupport
@@ -17,11 +19,11 @@ if defined?(Rails)
17
19
 
18
20
  if servers = ENV['MEMCACHED_SERVERS']
19
21
  Remix::Stash.define_cluster(:environment => servers.split(','))
20
- stash.default(:cluster => :environment)
22
+ Remix.stash.default(:cluster => :environment)
21
23
  end
22
24
 
23
25
  if namespace = ENV['MEMCACHED_NAMESPACE']
24
- stash.default(:namespace => namespace)
26
+ Remix.stash.default(:namespace => namespace)
25
27
  end
26
28
 
27
29
  end
data/remix-stash.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{remix-stash}
8
- s.version = "1.0.4"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Mitchell"]
12
- s.date = %q{2009-10-23}
12
+ s.date = %q{2009-12-01}
13
13
  s.email = %q{binary42@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "examples/stash.rb",
32
32
  "harness.rb",
33
33
  "init.rb",
34
+ "lib/active_support/cache/remix_stash_store.rb",
34
35
  "lib/remix/stash.rb",
35
36
  "lib/remix/stash/auto_detection.rb",
36
37
  "lib/remix/stash/cluster.rb",
@@ -38,6 +39,7 @@ Gem::Specification.new do |s|
38
39
  "lib/remix/stash/protocol.rb",
39
40
  "lib/remix/stash/runtime.rb",
40
41
  "remix-stash.gemspec",
42
+ "spec/active_support_cache_spec.rb",
41
43
  "spec/auto_detection_spec.rb",
42
44
  "spec/extension_spec.rb",
43
45
  "spec/spec.rb",
@@ -95,7 +97,8 @@ Gem::Specification.new do |s|
95
97
  s.rubygems_version = %q{1.3.1}
96
98
  s.summary = %q{Remix your memcache}
97
99
  s.test_files = [
98
- "spec/auto_detection_spec.rb",
100
+ "spec/active_support_cache_spec.rb",
101
+ "spec/auto_detection_spec.rb",
99
102
  "spec/extension_spec.rb",
100
103
  "spec/spec.rb",
101
104
  "spec/stash_spec.rb",
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/spec'
2
+
3
+ class ActiveSupportCacheSpec < Spec
4
+
5
+ context "ActiveSupport::Cache" do
6
+ context "looking up the cache store" do
7
+ setup do
8
+ @cache = ActiveSupport::Cache.lookup_store(:remix_stash_store, 'localhost:11211', :some_opt => 'namespace')
9
+ end
10
+
11
+ should "return a remix stash store" do
12
+ assert @cache.is_a?(ActiveSupport::Cache::RemixStashStore)
13
+ end
14
+
15
+ should "set default options passed as a hash" do
16
+ assert_equal 'namespace', Remix::Stash.new(:active_support_cache).default[:some_opt]
17
+ end
18
+ end
19
+
20
+ context "with a cache" do
21
+ setup do
22
+ @cache = ActiveSupport::Cache.lookup_store(:remix_stash_store, 'localhost:11211')
23
+ @stash = Remix::Stash.new(:active_support_cache)
24
+ end
25
+
26
+ teardown do
27
+ @stash.clear
28
+ end
29
+
30
+ should "write key" do
31
+ @cache.write('foo', 'bar')
32
+ assert_equal 'bar', @stash['foo']
33
+ end
34
+
35
+ should "read key" do
36
+ @stash['foo'] = 'bar'
37
+ assert_equal 'bar', @cache.read('foo')
38
+ end
39
+
40
+ should "delete key" do
41
+ @stash['foo'] = 'bar'
42
+ assert_equal 'bar', @cache.read('foo')
43
+ @cache.delete('foo')
44
+ assert_nil @cache.read('foo')
45
+ end
46
+
47
+ should "return true if key exists" do
48
+ @stash['foo'] = 'bar'
49
+ assert @cache.exist?('foo')
50
+ end
51
+
52
+ should "return false if key does not exist" do
53
+ assert !@cache.exist?('foo')
54
+ end
55
+
56
+ should "clear all keys" do
57
+ @stash['foo'] = 'bar'
58
+ assert_equal 'bar', @cache.read('foo')
59
+ @cache.clear
60
+ assert !@cache.exist?('foo')
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+
68
+ end
@@ -1,6 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec'
2
2
 
3
3
  class AutoDetectionSpec < Spec
4
+ include Remix
4
5
 
5
6
  context 'Rails' do
6
7
 
@@ -2,22 +2,22 @@ require File.dirname(__FILE__) + '/spec'
2
2
 
3
3
  class ExtensionSpec < Spec
4
4
 
5
- context '#stash' do
5
+ context 'Remix#stash' do
6
6
 
7
7
  should 'return a stash object with the correct name' do
8
- s = stash(:a)
8
+ s = Remix.stash(:a)
9
9
  assert_instance_of Stash, s
10
10
  assert_equal :a, s.name
11
11
  end
12
12
 
13
13
  should 'return the same object when given the same name' do
14
- assert_equal stash(:b), stash(:b)
15
- assert_not_equal stash(:a), stash(:b)
14
+ assert_equal Remix.stash(:b), Remix.stash(:b)
15
+ assert_not_equal Remix.stash(:a), Remix.stash(:b)
16
16
  end
17
17
 
18
18
  should 'allow access to a default root stash' do
19
- assert_equal stash, stash(:root)
20
- assert_equal :root, stash.name
19
+ assert_equal Remix.stash, Remix.stash(:root)
20
+ assert_equal :root, Remix.stash.name
21
21
  end
22
22
 
23
23
  end
data/spec/stash_spec.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec'
2
2
 
3
3
  class StashSpec < Spec
4
+ include Remix
4
5
 
5
6
  def setup
6
7
  stash.clear
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remix-stash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Mitchell
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-23 00:00:00 -04:00
12
+ date: 2009-12-01 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -38,6 +38,7 @@ files:
38
38
  - examples/stash.rb
39
39
  - harness.rb
40
40
  - init.rb
41
+ - lib/active_support/cache/remix_stash_store.rb
41
42
  - lib/remix/stash.rb
42
43
  - lib/remix/stash/auto_detection.rb
43
44
  - lib/remix/stash/cluster.rb
@@ -45,6 +46,7 @@ files:
45
46
  - lib/remix/stash/protocol.rb
46
47
  - lib/remix/stash/runtime.rb
47
48
  - remix-stash.gemspec
49
+ - spec/active_support_cache_spec.rb
48
50
  - spec/auto_detection_spec.rb
49
51
  - spec/extension_spec.rb
50
52
  - spec/spec.rb
@@ -121,6 +123,7 @@ signing_key:
121
123
  specification_version: 2
122
124
  summary: Remix your memcache
123
125
  test_files:
126
+ - spec/active_support_cache_spec.rb
124
127
  - spec/auto_detection_spec.rb
125
128
  - spec/extension_spec.rb
126
129
  - spec/spec.rb