rolex 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Rolex
2
2
 
3
- Redis-backed roles for Rails applications
3
+ Redis-backed roles for Rails applications.
4
+
5
+ ## To use in a Rails application
6
+
7
+ Create an initializer:
8
+
9
+ Rolex.redis = (Redis.current || ENV['REDISTOGO_URL'] || whatever)
4
10
 
5
11
  Include Rolex into your model:
6
12
 
data/lib/rolex.rb CHANGED
@@ -1,8 +1,48 @@
1
1
  require "rolex/version"
2
+ require "redis/namespace"
2
3
 
3
4
  # ROLEX - Redis backed roles
4
5
 
5
6
  module Rolex
7
+
8
+ #
9
+ # Lifted directly from Split: https://github.com/andrew/split/blob/master/lib/split.rb#L12-L37
10
+ #
11
+ # Accepts:
12
+ # 1. A 'hostname:port' string
13
+ # 2. A 'hostname:port:db' string (to select the Redis db)
14
+ # 3. A 'hostname:port/namespace' string (to set the Redis namespace)
15
+ # 4. A redis URL string 'redis://host:port'
16
+ # 5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
17
+ # or `Redis::Namespace`.
18
+ def self.redis=(server)
19
+ if server.respond_to? :split
20
+ if server["redis://"]
21
+ redis = Redis.connect(:url => server, :thread_safe => true)
22
+ else
23
+ server, namespace = server.split('/', 2)
24
+ host, port, db = server.split(':')
25
+ redis = Redis.new(:host => host, :port => port,
26
+ :thread_safe => true, :db => db)
27
+ end
28
+ namespace ||= :rolex
29
+
30
+ @redis = Redis::Namespace.new(namespace, :redis => redis)
31
+ elsif server.respond_to? :namespace=
32
+ @redis = server
33
+ else
34
+ @redis = Redis::Namespace.new(:rolex, :redis => server)
35
+ end
36
+ end
37
+
38
+ # Returns the current Redis connection. If none has been created, will
39
+ # create a new one.
40
+ def self.redis
41
+ return @redis if @redis
42
+ self.redis = 'localhost:6379'
43
+ self.redis
44
+ end
45
+
6
46
  extend ActiveSupport::Concern
7
47
 
8
48
  SUFFIX = ENV['RAILS_ENV'] || 'development'
data/lib/rolex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rolex
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/rolex.gemspec CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
+ gem.add_dependency "redis"
22
+ gem.add_dependency "redis-namespace"
23
+
21
24
  gem.add_development_dependency "rake"
22
25
  gem.add_development_dependency "rspec"
23
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rolex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-13 00:00:00.000000000 Z
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: &70136573936260 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70136573936260
25
+ - !ruby/object:Gem::Dependency
26
+ name: redis-namespace
27
+ requirement: &70136573934840 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70136573934840
14
36
  - !ruby/object:Gem::Dependency
15
37
  name: rake
16
- requirement: &70270640207960 !ruby/object:Gem::Requirement
38
+ requirement: &70136573933100 !ruby/object:Gem::Requirement
17
39
  none: false
18
40
  requirements:
19
41
  - - ! '>='
@@ -21,10 +43,10 @@ dependencies:
21
43
  version: '0'
22
44
  type: :development
23
45
  prerelease: false
24
- version_requirements: *70270640207960
46
+ version_requirements: *70136573933100
25
47
  - !ruby/object:Gem::Dependency
26
48
  name: rspec
27
- requirement: &70270640205340 !ruby/object:Gem::Requirement
49
+ requirement: &70136573932040 !ruby/object:Gem::Requirement
28
50
  none: false
29
51
  requirements:
30
52
  - - ! '>='
@@ -32,7 +54,7 @@ dependencies:
32
54
  version: '0'
33
55
  type: :development
34
56
  prerelease: false
35
- version_requirements: *70270640205340
57
+ version_requirements: *70136573932040
36
58
  description: ! 'Rolex: simple roles, backed by redis'
37
59
  email:
38
60
  - electronicbattleweapon7@gmail.com