rolex 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/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/lib/rolex.rb +25 -0
- data/lib/rolex/version.rb +3 -0
- data/rolex.gemspec +23 -0
- data/spec/rolex_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +81 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adam
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Rolex
|
2
|
+
|
3
|
+
Redis-backed roles for Rails applications
|
4
|
+
|
5
|
+
Include Rolex into your model:
|
6
|
+
|
7
|
+
class User < ActiveRecord::Base
|
8
|
+
include Rolex
|
9
|
+
end
|
10
|
+
|
11
|
+
Then:
|
12
|
+
|
13
|
+
> user.add_role :admin
|
14
|
+
=> true
|
15
|
+
|
16
|
+
> user.has_role? :admin
|
17
|
+
=> true
|
18
|
+
|
19
|
+
> user.roles
|
20
|
+
=> ['roles']
|
21
|
+
|
22
|
+
Roles are unique - if in doubt, add it.
|
23
|
+
|
24
|
+
A model can have as many roles as you like.
|
25
|
+
|
26
|
+
Roles can be anything you like.
|
27
|
+
|
28
|
+
## TODO
|
29
|
+
|
30
|
+
Add tests!
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
gem 'rolex'
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle
|
41
|
+
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install rolex
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
TODO: Write usage instructions here
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/rolex.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "rolex/version"
|
2
|
+
|
3
|
+
# ROLEX - Redis backed roles
|
4
|
+
|
5
|
+
module Rolex
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
def add_role(role)
|
10
|
+
Redis.current.sadd "user:#{id}:rolex:#{ENV['RAILS_ENV']}", role.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_role?(role)
|
14
|
+
Redis.current.smembers("user:#{id}:rolex:#{ENV['RAILS_ENV']}").include? role.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def roles
|
18
|
+
Redis.current.smembers("user:#{id}:rolex:#{ENV['RAILS_ENV']}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def remove_role(role)
|
22
|
+
Redis.current.srem "user:#{id}:rolex:#{ENV['RAILS_ENV']}", role.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/rolex.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rolex/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rolex"
|
8
|
+
gem.version = Rolex::VERSION
|
9
|
+
gem.authors = ["Adam"]
|
10
|
+
gem.email = ["electronicbattleweapon7@gmail.com"]
|
11
|
+
gem.description = %q{Rolex: simple roles, backed by redis}
|
12
|
+
gem.summary = %q{Rolex: simple roles, backed by redis}
|
13
|
+
gem.homepage = ""
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "rspec"
|
23
|
+
end
|
data/spec/rolex_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rolex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70162146503040 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70162146503040
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70162146502620 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70162146502620
|
36
|
+
description: ! 'Rolex: simple roles, backed by redis'
|
37
|
+
email:
|
38
|
+
- electronicbattleweapon7@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rspec
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE.txt
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- lib/rolex.rb
|
50
|
+
- lib/rolex/version.rb
|
51
|
+
- rolex.gemspec
|
52
|
+
- spec/rolex_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: ''
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.11
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: ! 'Rolex: simple roles, backed by redis'
|
79
|
+
test_files:
|
80
|
+
- spec/rolex_spec.rb
|
81
|
+
- spec/spec_helper.rb
|