jsl-hashpipe 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/hashpipe.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hashpipe"
3
- s.version = "0.0.2"
4
- s.date = "2009-04-12"
5
- s.summary = "Rails plugin to save content to a pluggable, hash-style backend"
3
+ s.version = "0.0.3"
4
+ s.date = "2009-05-12"
5
+ s.summary = "ActiveRecord plugin to save content to a pluggable, hash-style backend"
6
6
  s.email = "justin@phq.org"
7
7
  s.homepage = "http://github.com/jsl/hashpipe"
8
- s.description = "HashPipe allows for data to be saved to a backend other than the rdbms"
8
+ s.description = "HashPipe connects an AR-backed model to a key-value store"
9
9
  s.has_rdoc = true
10
10
  s.authors = ["Justin Leitgeb"]
11
11
  s.files = [
@@ -17,15 +17,17 @@ Gem::Specification.new do |s|
17
17
  "lib/hashpipe/archived_attribute.rb",
18
18
  "lib/hashpipe/global_configuration.rb",
19
19
  "lib/hashpipe/backends/s3.rb",
20
+ "lib/hashpipe/backends/memcache.rb",
20
21
  "lib/hashpipe/backends/filesystem.rb"
21
22
  ]
22
23
  s.test_files = [
23
24
  "spec/hashpipe/global_configuration_spec.rb",
24
25
  "spec/hashpipe/archived_attribute_spec.rb",
25
26
  "spec/hashpipe/backends/filesystem_spec.rb",
26
- "spec/hashpipe/backends/s3_spec.rb"
27
+ "spec/hashpipe/backends/s3_spec.rb",
28
+ "spec/hashpipe/backends/memcache_spec.rb"
27
29
  ]
28
-
30
+ s.add_dependency("activesupport", ["> 0.0.0"])
29
31
  s.add_dependency("right_aws", ["> 0.0.0"])
30
32
  s.add_dependency("assaf-uuid", ["> 0.0.0"])
31
33
  end
data/init.rb CHANGED
@@ -1,4 +1 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), %w[lib hashpipe]))
2
-
3
- ActiveRecord::Base.send(:include, HashPipe)
4
-
1
+ require 'hashpipe'
@@ -41,6 +41,7 @@ module HashPipe
41
41
  # error, we capture it and add it to the AR validation errors.
42
42
  def save
43
43
  @backend.save(@stashed_value) if self.dirty?
44
+ @dirty = false
44
45
  end
45
46
 
46
47
  def destroy
@@ -0,0 +1,42 @@
1
+ module HashPipe
2
+ module Backends
3
+
4
+ class Memcache
5
+
6
+ def initialize(archived_attribute)
7
+ @archived_attribute = archived_attribute
8
+ @config = HashPipe::GlobalConfiguration.instance[:memcache]
9
+ end
10
+
11
+ def save(content)
12
+ cache.write( key_name, content ) unless content.nil?
13
+ end
14
+
15
+ def destroy
16
+ cache.delete(key_name)
17
+ end
18
+
19
+ def load
20
+ cache.read(key_name)
21
+ end
22
+
23
+ private
24
+
25
+ def cache
26
+ @cache ||= ActiveSupport::Cache::MemCacheStore.new(server)
27
+ end
28
+
29
+ def key_name
30
+ [ @archived_attribute.instance.class.table_name,
31
+ @archived_attribute.name,
32
+ @archived_attribute.instance.uuid ].join('/')
33
+ end
34
+
35
+ def server
36
+ "#{@config[:server]}:#{@config[:port]}"
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -16,7 +16,8 @@ module HashPipe
16
16
  :archive_root => nil
17
17
  },
18
18
  :memcache => {
19
- :port => 1978
19
+ :port => 1978,
20
+ :server => 'localhost'
20
21
  }
21
22
  })
22
23
 
data/lib/hashpipe.rb CHANGED
@@ -77,4 +77,6 @@ module HashPipe
77
77
  end
78
78
 
79
79
  end
80
- end
80
+ end
81
+
82
+ ActiveRecord::Base.send(:include, HashPipe)
@@ -16,6 +16,13 @@ describe HashPipe::ArchivedAttribute do
16
16
  @aa.value = 'stuff'
17
17
  @aa.should be_dirty
18
18
  end
19
+
20
+ it "should not be dirty after save is called" do
21
+ @aa.value = 'stuff'
22
+ @aa.should be_dirty
23
+ @aa.save
24
+ @aa.should_not be_dirty
25
+ end
19
26
  end
20
27
 
21
28
  describe "#marshal?" do
@@ -0,0 +1,56 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. .. spec_helper ])
2
+
3
+ describe HashPipe::Backends::Memcache do
4
+
5
+ before do
6
+ @instance = stub('ar_instance',
7
+ :uuid => '63d3a120-caca-012b-d468-002332d4f91e',
8
+ :table_name => 'glorps'
9
+ )
10
+
11
+ @aa = HashPipe::ArchivedAttribute.new(:stuff, @instance)
12
+ @mc = HashPipe::Backends::Memcache.new(@aa)
13
+ @mc.stubs(:key_name).returns('foo-key')
14
+
15
+ @mock_store = mock('memcache_store')
16
+ @mc.stubs(:cache).returns(@mock_store)
17
+ end
18
+
19
+ describe "#initialize" do
20
+ it "should initialize a memcached object without error" do
21
+ lambda { HashPipe::Backends::Memcache.new(@aa) }.should_not raise_error
22
+ end
23
+ end
24
+
25
+ describe "#load" do
26
+ it "should call method to load data from memcached" do
27
+ @mock_store.expects(:read)
28
+ @mc.load
29
+ end
30
+ end
31
+
32
+ describe "#save" do
33
+ it "should call method to store data in memcached" do
34
+ @mock_store.expects(:write)
35
+ @mc.save('content')
36
+ end
37
+ end
38
+
39
+ describe "#destroy" do
40
+ it "should call method to delete key" do
41
+ @mock_store.expects(:delete)
42
+ @mc.destroy
43
+ end
44
+ end
45
+
46
+ describe "#server" do
47
+ before do
48
+ @backend = HashPipe::Backends::Memcache.new(:foo)
49
+ end
50
+
51
+ it "should return server:port" do
52
+ @backend.instance_variable_set(:@config, :memcache => {:server => 'foo', :port => 1978})
53
+ @backend.__send__(:server).should == "foo:1978"
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsl-hashpipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Leitgeb
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-12 00:00:00 -07:00
12
+ date: 2009-05-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: right_aws
17
27
  type: :runtime
@@ -32,7 +42,7 @@ dependencies:
32
42
  - !ruby/object:Gem::Version
33
43
  version: 0.0.0
34
44
  version:
35
- description: HashPipe allows for data to be saved to a backend other than the rdbms
45
+ description: HashPipe connects an AR-backed model to a key-value store
36
46
  email: justin@phq.org
37
47
  executables: []
38
48
 
@@ -49,6 +59,7 @@ files:
49
59
  - lib/hashpipe/archived_attribute.rb
50
60
  - lib/hashpipe/global_configuration.rb
51
61
  - lib/hashpipe/backends/s3.rb
62
+ - lib/hashpipe/backends/memcache.rb
52
63
  - lib/hashpipe/backends/filesystem.rb
53
64
  has_rdoc: true
54
65
  homepage: http://github.com/jsl/hashpipe
@@ -75,9 +86,10 @@ rubyforge_project:
75
86
  rubygems_version: 1.2.0
76
87
  signing_key:
77
88
  specification_version: 2
78
- summary: Rails plugin to save content to a pluggable, hash-style backend
89
+ summary: ActiveRecord plugin to save content to a pluggable, hash-style backend
79
90
  test_files:
80
91
  - spec/hashpipe/global_configuration_spec.rb
81
92
  - spec/hashpipe/archived_attribute_spec.rb
82
93
  - spec/hashpipe/backends/filesystem_spec.rb
83
94
  - spec/hashpipe/backends/s3_spec.rb
95
+ - spec/hashpipe/backends/memcache_spec.rb