Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial

  • Loading branch information...
commit e36aec2f0ac292988489c152337c5dea86d56625 0 parents
@nu7hatch authored
11 .gitignore
@@ -0,0 +1,11 @@
+.DS_Store
+*.tmproj
+tmtags
+*~
+\#*
+.\#*
+*.swp
+coverage
+rdoc
+pkg
+*.rdb
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Kriss 'nu7hatch' Kowalik
+
+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:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+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.
59 README.rdoc
@@ -0,0 +1,59 @@
+= Redis Aid
+
+Small lib which helps with extending your classes or modules with redis (and nest) goodies.
+
+== Installation
+
+From rubygems:
+
+ gem install redis-aid # with sudo if necessary
+
+== Examples
+
+You can configure global redis connection:
+
+ Redis::Aid.redis = Redis.new
+
+Simple usage:
+
+ class MyClass
+ include Redis::Aid
+
+ def foo
+ redis.get(:foo)
+ end
+ end
+
+Powered by nest:
+
+ class MySecondClass
+ include Redis::Aid::Ns(:foo)
+
+ def bar
+ redis[:bar].get # => value of 'foo.bar'
+ end
+
+ def spam_and_eggs
+ redis[:spam][:eggs].get # => value of 'foo.spam.eggs'
+ end
+
+Custom redis connection? No problem:
+
+ class MyThirdClass
+ include Redis::Aid
+ redis = Redis.connect(:host => "host.com")
+ end
+
+== Note on Patches/Pull Requests
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a
+ future version unintentionally.
+* Commit, do not mess with rakefile, version, or history.
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
+* Send me a pull request. Bonus points for topic branches.
+
+== Copyright
+
+Copyright (c) 2010 Kriss 'nu7hatch' Kowalik. See LICENSE for details.
46 Rakefile
@@ -0,0 +1,46 @@
+# -*- ruby -*-
+$:.unshift(File.expand_path('../lib', __FILE__))
+
+require 'rspec/core/rake_task'
+require 'rake/rdoctask'
+require 'redis-aid'
+
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.pattern = 'spec/**/*_spec.rb'
+ t.rspec_opts = %q[-c -b]
+end
+
+RSpec::Core::RakeTask.new(:rcov) do |t|
+ t.rcov = true
+ t.rspec_opts = %q[-c -b]
+ t.rcov_opts = %q[-T -x "spec"]
+end
+
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "Redis Aid #{Redis::Aid.version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+task :default => :spec
+
+desc "Build current version as a rubygem"
+task :build do
+ `gem build redis-aid.gemspec`
+ `mkdir -p pkg`
+ `mv redis-aid-*.gem pkg/`
+end
+
+desc "Relase current version to rubygems.org"
+task :release => :build do
+ `git tag -am "Version bump to #{Redis::Aid.version}" v#{Redis::Aid.version}`
+ `git push origin master`
+ `git push origin master --tags`
+ `gem push pkg/redis-aid-#{Redis::Aid.version}.gem`
+end
+
+desc "Perform installation via rubygems"
+task :install => :build do
+ `gem install pkg/redis-aid-#{Redis::Aid.version}.gem`
+end
57 lib/redis_aid.rb
@@ -0,0 +1,57 @@
+require "redis"
+require "nest"
+
+class Redis
+ module Aid
+ class << self
+ def version
+ "0.0.1"
+ end
+
+ attr_accessor :redis
+
+ def redis
+ @redis ||= Redis.new
+ end
+
+ def Namespace(ns)
+ Redis::Aid.instance_variable_set("@ns", ns)
+ Redis::Aid
+ end
+ alias :Ns :Namespace
+ end # << self
+
+ module ClassMethods
+ attr_accessor :redis
+
+ def redis
+ @redis ||= Redis::Aid.redis
+ end
+
+ def ns=(namespace)
+ @ns = Nest.new(namespace)
+ end
+
+ def ns
+ @ns ||= Nest.new
+ end
+ end # ClassMethods
+
+ module InstanceMethods
+ def redis
+ self.class.redis
+ end
+
+ def ns
+ self.class.ns
+ end
+ end # InstanceMethods
+
+ def self.included(receiver) # :nodoc:
+ receiver.send :extend, ClassMethods
+ receiver.send :include, InstanceMethods
+ receiver.instance_variable_set("@ns", @ns) and @ns = nil if @ns
+ end
+
+ end # Aid
+end # Redis
22 redis-aid.gemspec
@@ -0,0 +1,22 @@
+# -*- ruby -*-
+$:.unshift(File.expand_path('../lib', __FILE__))
+require 'redis-aid'
+
+Gem::Specification.new do |s|
+ s.name = 'redis-aid'
+ s.version = Redis::Aid.version
+ s.homepage = 'http://github.com/nu7hatch/redis-aid'
+ s.email = ['chris@nu7hat.ch']
+ s.authors = ['Chris Kowalik']
+ s.summary = %q{Flexible access control mechanism!}
+ s.description = %q{Small lib which helps with extending your classes or modules with redis (and nest) goodies.}
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
+ s.require_paths = %w[lib]
+ s.extra_rdoc_files = %w[LICENSE README.rdoc]
+
+ s.add_runtime_dependency 'redis', [">= 2.0"]
+ s.add_runtime_dependency 'nest', [">= 0"]
+ s.add_development_dependency 'rspec', ["~> 2.0"]
+ s.add_development_dependency 'mocha', [">= 0.9"]
+end
7 spec/spec_helper.rb
@@ -0,0 +1,7 @@
+require "rspec"
+require "mocha"
+require "redis-aid"
+
+RSpec.configured do |conf|
+ conf.mock_with :mocha
+end
Please sign in to comment.
Something went wrong with that request. Please try again.