jsl-hashback 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Justin S. Leitgeb
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ = HashBack
2
+
3
+ Provides a general interface over Moneta which allows namespacing of key values and the requirement of correct
4
+ Moneta backend class.
5
+
6
+ == Author
7
+
8
+ Justin S. Leitgeb, <justin@phq.org>
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ require 'rake'
5
+ require 'spec/rake/spectask'
6
+ require 'rake/rdoctask'
7
+
8
+ desc 'Test the plugin.'
9
+ Spec::Rake::SpecTask.new(:spec) do |t|
10
+ t.spec_opts = ["--format", "specdoc", "--colour"]
11
+ t.libs << 'lib'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc "Run all the tests"
16
+ task :default => :spec
17
+
18
+ desc 'Generate documentation for the hashback plugin.'
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'HashBack'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
data/hashback.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "hashback"
3
+ s.version = "0.0.1.1"
4
+ s.date = "2009-05-13"
5
+ s.summary = "Generic tool for writing namespaced key-value data to a variety of hash-type systems"
6
+ s.email = "justin@phq.org"
7
+ s.homepage = "http://github.com/jsl/hashback"
8
+ s.description = "Wrapper around Moneta that facilitates using the key-value store as a backend for applications requiring namespacing"
9
+ s.has_rdoc = true
10
+ s.authors = ["Justin Leitgeb"]
11
+ s.files = [
12
+ "Rakefile",
13
+ "hashback.gemspec",
14
+ "init.rb",
15
+ "LICENSE",
16
+ "README.rdoc",
17
+ "Rakefile",
18
+ "lib/hashback.rb",
19
+ "lib/hashback/backend.rb"
20
+ ]
21
+ s.test_files = [
22
+ "spec/hashback/backend_spec.rb",
23
+ "spec/hashback_spec.rb",
24
+ "spec/spec_helper.rb"
25
+ ]
26
+ s.add_dependency("wycats-moneta", ["> 0.0.0"])
27
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'hashback'
data/lib/hashback.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'moneta'
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[hashback backend] ))
@@ -0,0 +1,50 @@
1
+ module HashBack
2
+
3
+ # Delegates methods to Moneta (a unified interface to key-value storage systems) after adding
4
+ # a key for proper namespacing. Initializes and loads the proper Moneta class based on input
5
+ # options, and delegates setting and retrieval to the Moneta class responsible for storage.
6
+ class Backend
7
+
8
+ def initialize(namespace, moneta_klass, options = { })
9
+ @namespace = namespace
10
+ @options = options
11
+ @cache = initialize_cache_klass(moneta_klass)
12
+ end
13
+
14
+ def [](key)
15
+ @cache[key_name_for(key)]
16
+ end
17
+
18
+ def []=(key, value)
19
+ @cache[key_name_for(key)] = value
20
+ end
21
+
22
+ def delete(key)
23
+ @cache.delete(key_name_for(key))
24
+ end
25
+
26
+ private
27
+
28
+ def initialize_cache_klass(cache_klass)
29
+ require_moneta_library_for(cache_klass)
30
+ klass_const = cache_klass.respond_to?(:constantize) ? cache_klass.constantize : cache_klass
31
+ klass_const.new(@options)
32
+ end
33
+
34
+ def require_moneta_library_for(cache_klass)
35
+ require_klass(cache_klass.to_s.gsub(/::/, '/').downcase)
36
+ end
37
+
38
+ def require_klass(klass)
39
+ require klass
40
+ end
41
+
42
+ def key_name_for(key)
43
+ [ @namespace, key ].join('-')
44
+ end
45
+
46
+ def table_name_from(archived_attribute)
47
+ archived_attribute.instance.class.table_name
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper ])
2
+
3
+ describe HashBack::Backend do
4
+ before do
5
+ @moneta = mock('moneta')
6
+ HashBack::Backend.any_instance.stubs(:initialize_cache_klass).returns(@moneta)
7
+ @b = HashBack::Backend.new('foo', 'MonetaKlass', { })
8
+ @b.stubs(:key_name_for).returns('keyname')
9
+ end
10
+
11
+ describe "methods proxied to backend" do
12
+ describe "#[]" do
13
+ it "should call the backend with the key name" do
14
+ @moneta.expects(:[]).with('keyname')
15
+ @b['keyname']
16
+ end
17
+ end
18
+
19
+ describe "#[]=" do
20
+ it "should call the backend with the key name and value" do
21
+ @moneta.expects(:[]=).with('keyname', 'value')
22
+ @b['keyname'] = 'value'
23
+ end
24
+ end
25
+
26
+ describe "#delete" do
27
+ it "should call delete for this key name on the backend" do
28
+ @moneta.expects(:delete).with('keyname')
29
+ @b.delete('foo')
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe HashBack do
4
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'mocha'
3
+ require 'spec'
4
+
5
+ Spec::Runner.configure do |config|
6
+ config.mock_with(:mocha)
7
+ end
8
+
9
+ require File.join(File.dirname(__FILE__), %w[.. init])
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsl-hashback
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Leitgeb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: wycats-moneta
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:
25
+ description: Wrapper around Moneta that facilitates using the key-value store as a backend for applications requiring namespacing
26
+ email: justin@phq.org
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - Rakefile
35
+ - hashback.gemspec
36
+ - init.rb
37
+ - LICENSE
38
+ - README.rdoc
39
+ - lib/hashback.rb
40
+ - lib/hashback/backend.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/jsl/hashback
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.2.0
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: Generic tool for writing namespaced key-value data to a variety of hash-type systems
67
+ test_files:
68
+ - spec/hashback/backend_spec.rb
69
+ - spec/hashback_spec.rb
70
+ - spec/spec_helper.rb