rubis 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Ryan Carmelo Briones <ryan.briones@brionesandco.com>
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,23 @@
1
+ = Rubis
2
+
3
+ API for redis-backed ruby objects
4
+
5
+ == Usage
6
+
7
+ Rubis.redis = 'localhost:6379'
8
+ module Foo
9
+ class Bar
10
+ extend Rubis::Namespace
11
+ end
12
+ end
13
+
14
+ Foo::Bar.rpush('key', 'value')
15
+ # => redis.rpush('foo:bar:key', 'value')
16
+
17
+ == TODO
18
+
19
+ * API for persistent objects
20
+
21
+ == Author
22
+
23
+ Ryan Carmelo Briones <ryan.briones@brionesandco.com>
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ require File.expand_path(File.dirname(__FILE__) + '/lib/rubis')
5
+
6
+ spec = Gem::Specification.new do |s|
7
+ s.name = 'rubis'
8
+ s.version = Rubis::VERSION
9
+ s.homepage = 'http://github.com/ryanbriones/rubis'
10
+ s.summary = 'API for redis-backed ruby objects'
11
+ s.files = FileList['[A-Z]*', 'lib/rubis.rb', 'lib/rubis/*.rb', 'spec/*']
12
+ s.has_rdoc = false
13
+ s.author = 'Ryan Carmelo Briones'
14
+ s.email = 'ryan.briones@brionesandco.com'
15
+
16
+ s.add_dependency 'redis-rb', '> 0.0.0'
17
+ end
18
+
19
+ package_task = Rake::GemPackageTask.new(spec) {}
20
+
21
+ desc "Write out #{spec.name}.gemspec"
22
+ task :build_gemspec do
23
+ File.open("#{spec.name}.gemspec", "w") do |f|
24
+ f.write spec.to_ruby
25
+ end
26
+ end
27
+
28
+ task :default => [:build_gemspec, :gem]
data/lib/rubis.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'redis'
2
+
3
+ module Rubis
4
+ VERSION = '0.0.1'
5
+
6
+ autoload :Namespace, 'rubis/namespace'
7
+
8
+ def self.redis=(connection)
9
+ case connection
10
+ when String
11
+ host, port, db = server.split(':')
12
+ @redis = Redis.new(:host => host, :port => port,
13
+ :thread_safe => true, :db => db)
14
+ when Redis
15
+ @redis = server
16
+ else
17
+ raise "I don't know what to do with #{connection.inspect}"
18
+ end
19
+ end
20
+
21
+ def self.redis
22
+ return @redis if @redis
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ module Rubis
2
+ module Namespace
3
+ def self.extended(base)
4
+ base.class_eval { @rubis_namespace = base.to_s.downcase.gsub('::', ':') }
5
+ end
6
+
7
+ def redis_namespace
8
+ self.class_eval { @rubis_namespace }
9
+ end
10
+
11
+ private
12
+
13
+ def redis
14
+ Rubis.redis
15
+ end
16
+
17
+ def method_missing(method, *args, &block)
18
+ key = "#{redis_namespace}:#{args.shift}"
19
+ redis.send(method, key, *args, &block)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
+
3
+
4
+ describe Rubis::Namespace do
5
+ describe "namespace" do
6
+ it "should be klass when extending Klass" do
7
+ with_rubis_namespace_class(:Klass) do
8
+ Klass.class_eval { @rubis_namespace }.should == "klass"
9
+ end
10
+ end
11
+
12
+ it "should be foo when extending Foo" do
13
+ with_rubis_namespace_class(:Foo) do
14
+ Foo.class_eval { @rubis_namespace }.should == "foo"
15
+ end
16
+ end
17
+
18
+ it "should be parent:child when extending Parent::Child" do
19
+ with_rubis_namespace_class(:Parent, :Child) do
20
+ Parent::Child.class_eval { @rubis_namespace }.should == "parent:child"
21
+ end
22
+ end
23
+
24
+ it "should call the redis function with namespaced key" do
25
+ with_rubis_namespace_class(:Klass) do
26
+ redis = mock('redis')
27
+ Klass.stub(:redis => redis)
28
+
29
+ redis.should_receive(:rpush).with("klass:key", "value")
30
+ Klass.rpush("key", "value")
31
+ end
32
+ end
33
+ end
34
+
35
+ def with_rubis_namespace_class(*args)
36
+ klass =
37
+ if args.size == 1
38
+ klass_obj = Class.new
39
+ Object.const_set(args[0], klass_obj)
40
+ else
41
+ klass_sym = args.pop
42
+ parents = args.inject([]) do |namespaces, name|
43
+ (namespaces.last || Object).module_eval do
44
+ namespaces << const_set(name, Module.new)
45
+ end
46
+ end
47
+
48
+ parents.last.module_eval do
49
+ klass_obj = Class.new
50
+ const_set(klass_sym, klass_obj)
51
+ end
52
+ end
53
+
54
+ klass.class_eval { extend Rubis::Namespace }
55
+ yield(klass)
56
+ Object.send(:remove_const, args[0])
57
+ end
58
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=progress
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/lib"))
2
+ require "rubis"
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Carmelo Briones
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-17 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: redis-rb
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:
26
+ email: ryan.briones@brionesandco.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - LICENSE
35
+ - Rakefile
36
+ - README.rdoc
37
+ - lib/rubis.rb
38
+ - lib/rubis/namespace.rb
39
+ - spec/rubis_namespace_spec.rb
40
+ - spec/spec.opts
41
+ - spec/spec_helper.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/ryanbriones/rubis
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: API for redis-backed ruby objects
70
+ test_files: []
71
+