role_model 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +2 -1
- data/README.rdoc +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/role_model/class_methods.rb +5 -1
- data/lib/role_model/roles.rb +6 -1
- data/role_model.gemspec +6 -8
- data/spec/role_model_spec.rb +39 -2
- metadata +73 -108
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NGIyYzhiNTFlOTRkZGZjOWQyMTVlM2I0Y2Y0Yjc3ZmU2MzYxY2M4OQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDI3MjlhODc2NzJiNDVmNDZkNWM2MjU1YTc3NTJiZmY0ZTk3ZWY3Mg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjgyZDdkNzE3ZDAzMjA0Mjg1YWUxMmFhYTEzZjg2OGQ5Y2NiYjhhOGJlOGUx
|
10
|
+
NDY2YzExNzNlMzIyODVjZTYyMjJkMDFlMDViNDlhMTFjYzRiMzQwOWY3Yzc2
|
11
|
+
OWUzOWYxYjJmY2UwNDVkNmYzMmFjNWYxZjA2YTVhNmU2ZmEzNTU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTAxNDA3NGVjNWNjMjcxOTUzM2NmYmNmMTIwNmJlNjRiZGUzNWJiMzA2NDli
|
14
|
+
YTFhZTIxMmNkYTNjYzIwZWQ2NDk0NGNiM2MzOWEzZmYyZjVjOWFkYmQxOTM1
|
15
|
+
ZDRmNjlkYjdmYTIyOWZkYTUyZTYxM2ZjNTJmOWYzM2VhMzI0NzU=
|
data/.travis.yml
CHANGED
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
RoleModel is the framework agnostic, efficient and declarative way to do
|
4
4
|
(user) roles. Assigned roles will be efficiently stored as a bitmask
|
5
|
-
directly into your model within
|
5
|
+
directly into your model within a configurable attribute.
|
6
6
|
|
7
7
|
It works like this:
|
8
8
|
|
@@ -12,7 +12,7 @@ It works like this:
|
|
12
12
|
|
13
13
|
class User
|
14
14
|
attr_accessor :roles_mask # just for demo purposes
|
15
|
-
# in real life this would
|
15
|
+
# in real life this would usually be a persistent attribute,
|
16
16
|
# e.g. if your User model is persisted in a SQL-DB add an integer
|
17
17
|
# column named roles_mask to your users table -- just remove/replace
|
18
18
|
# above attr_accessor line with whatever is needed for your
|
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ Jeweler::Tasks.new do |gem|
|
|
23
23
|
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
24
|
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
25
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
-
gem.add_development_dependency "rspec", "~> 2"
|
26
|
+
# gem.add_development_dependency "rspec", "~> 2"
|
27
27
|
end
|
28
28
|
Jeweler::RubygemsDotOrgTasks.new
|
29
29
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.2
|
@@ -23,7 +23,11 @@ module RoleModel
|
|
23
23
|
|
24
24
|
(valid_roles & sanitized_roles).inject(0) { |sum, role| sum + 2**valid_roles.index(role) }
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
def roles_from_mask(mask)
|
28
|
+
valid_roles.reject { |role| (mask.to_i & 2**valid_roles.index(role)).zero? }
|
29
|
+
end
|
30
|
+
|
27
31
|
protected
|
28
32
|
|
29
33
|
# :call-seq:
|
data/lib/role_model/roles.rb
CHANGED
@@ -14,10 +14,15 @@ module RoleModel
|
|
14
14
|
model_instance.roles = roles if model_instance
|
15
15
|
self
|
16
16
|
end
|
17
|
+
|
17
18
|
alias_method :<<, :add
|
18
19
|
|
19
20
|
def delete(role)
|
20
|
-
|
21
|
+
if role.is_a? Array
|
22
|
+
model_instance.roles = subtract(role)
|
23
|
+
else
|
24
|
+
model_instance.roles = super(role.to_sym)
|
25
|
+
end
|
21
26
|
self
|
22
27
|
end
|
23
28
|
|
data/role_model.gemspec
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: role_model 0.8.2 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "role_model"
|
8
|
-
s.version = "0.8.
|
9
|
+
s.version = "0.8.2"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
11
13
|
s.authors = ["Martin Rehfeld"]
|
12
|
-
s.date = "
|
14
|
+
s.date = "2015-02-12"
|
13
15
|
s.description = "Ever needed to assign roles to a model, say a User, and build conditional behaviour on top of that? Enter RoleModel -- roles have never been easier! Just declare your roles and you are done. Assigned roles will be stored as a bitmask."
|
14
16
|
s.email = "martin.rehfeld@glnetworks.de"
|
15
17
|
s.extra_rdoc_files = [
|
@@ -38,32 +40,28 @@ Gem::Specification.new do |s|
|
|
38
40
|
]
|
39
41
|
s.homepage = "http://github.com/martinrehfeld/role_model"
|
40
42
|
s.licenses = ["MIT"]
|
41
|
-
s.
|
42
|
-
s.rubygems_version = "1.8.23"
|
43
|
+
s.rubygems_version = "2.2.2"
|
43
44
|
s.summary = "Declare, assign and query roles with ease"
|
44
45
|
|
45
46
|
if s.respond_to? :specification_version then
|
46
|
-
s.specification_version =
|
47
|
+
s.specification_version = 4
|
47
48
|
|
48
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
50
|
s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
|
50
51
|
s.add_development_dependency(%q<rspec>, ["~> 2"])
|
51
52
|
s.add_development_dependency(%q<rdoc>, [">= 2.4.2"])
|
52
53
|
s.add_development_dependency(%q<autotest>, [">= 0"])
|
53
|
-
s.add_development_dependency(%q<rspec>, ["~> 2"])
|
54
54
|
else
|
55
55
|
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
56
56
|
s.add_dependency(%q<rspec>, ["~> 2"])
|
57
57
|
s.add_dependency(%q<rdoc>, [">= 2.4.2"])
|
58
58
|
s.add_dependency(%q<autotest>, [">= 0"])
|
59
|
-
s.add_dependency(%q<rspec>, ["~> 2"])
|
60
59
|
end
|
61
60
|
else
|
62
61
|
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
63
62
|
s.add_dependency(%q<rspec>, ["~> 2"])
|
64
63
|
s.add_dependency(%q<rdoc>, [">= 2.4.2"])
|
65
64
|
s.add_dependency(%q<autotest>, [">= 0"])
|
66
|
-
s.add_dependency(%q<rspec>, ["~> 2"])
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
data/spec/role_model_spec.rb
CHANGED
@@ -51,6 +51,31 @@ describe RoleModel do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
describe '.roles_from_mask(mask)' do
|
55
|
+
subject { model_class.roles_from_mask(mask) }
|
56
|
+
|
57
|
+
before do
|
58
|
+
model_class.instance_eval do
|
59
|
+
include RoleModel
|
60
|
+
roles :foo, :bar, :third
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when roles_mask is 0' do
|
65
|
+
let(:mask) { 0 }
|
66
|
+
it 'returns empty set' do
|
67
|
+
subject.should eq []
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when valid roles_mask' do
|
72
|
+
let(:mask) { 3 }
|
73
|
+
it 'returns the list of roles associated with a roles_mask' do
|
74
|
+
subject.should eq [:foo, :bar]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
54
79
|
[:roles, :role_symbols].each do |role_query_method|
|
55
80
|
describe "##{role_query_method}" do
|
56
81
|
let(:model) { model_class.new }
|
@@ -216,6 +241,18 @@ describe RoleModel do
|
|
216
241
|
subject.should have(1).roles
|
217
242
|
end
|
218
243
|
|
244
|
+
it "should delete existing roles given as an array of symbols" do
|
245
|
+
subject.roles.delete [:foo, :bar]
|
246
|
+
expect(subject.roles).not_to include([:foo, :bar])
|
247
|
+
expect(subject).to have(0).roles
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should delete existing roles given as an array of strings" do
|
251
|
+
subject.roles.delete %w(foo bar)
|
252
|
+
expect(subject.roles).not_to include([:foo, :bar])
|
253
|
+
expect(subject).to have(0).roles
|
254
|
+
end
|
255
|
+
|
219
256
|
it "should not change anything if a non existing role is given" do
|
220
257
|
subject.roles.delete(:third)
|
221
258
|
subject.roles.should include(:foo, :bar)
|
@@ -487,7 +524,7 @@ describe RoleModel do
|
|
487
524
|
end
|
488
525
|
|
489
526
|
context "inheritance" do
|
490
|
-
let(:superclass_instance) {
|
527
|
+
let(:superclass_instance) { model_class.new }
|
491
528
|
let(:inherited_model_class) { Class.new(model_class) }
|
492
529
|
subject { inherited_model_class.new }
|
493
530
|
|
@@ -538,7 +575,7 @@ describe RoleModel do
|
|
538
575
|
end
|
539
576
|
|
540
577
|
context "independent usage" do
|
541
|
-
let(:model_instance) {
|
578
|
+
let(:model_instance) { model_class.new }
|
542
579
|
let(:other_model_class) { Class.new }
|
543
580
|
before(:each) do
|
544
581
|
other_model_class.instance_eval do
|
metadata
CHANGED
@@ -1,106 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: role_model
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 8
|
9
|
-
- 1
|
10
|
-
version: 0.8.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Martin Rehfeld
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
-
none: false
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 7
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 5
|
30
|
-
- 2
|
31
|
-
version: 1.5.2
|
32
|
-
version_requirements: *id001
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
33
14
|
name: jeweler
|
34
|
-
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.2
|
35
20
|
type: :development
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
|
-
requirements:
|
40
|
-
- - ~>
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
hash: 7
|
43
|
-
segments:
|
44
|
-
- 2
|
45
|
-
version: "2"
|
46
|
-
version_requirements: *id002
|
47
|
-
name: rspec
|
48
21
|
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
49
34
|
type: :development
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
hash: 27
|
57
|
-
segments:
|
58
|
-
- 2
|
59
|
-
- 4
|
60
|
-
- 2
|
61
|
-
version: 2.4.2
|
62
|
-
version_requirements: *id003
|
63
|
-
name: rdoc
|
64
35
|
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.4.2
|
65
48
|
type: :development
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
|
-
requirements:
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
hash: 3
|
73
|
-
segments:
|
74
|
-
- 0
|
75
|
-
version: "0"
|
76
|
-
version_requirements: *id004
|
77
|
-
name: autotest
|
78
49
|
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.4.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: autotest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
79
62
|
type: :development
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
|
-
requirements:
|
84
|
-
- - ~>
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
hash: 7
|
87
|
-
segments:
|
88
|
-
- 2
|
89
|
-
version: "2"
|
90
|
-
version_requirements: *id005
|
91
|
-
name: rspec
|
92
63
|
prerelease: false
|
93
|
-
|
94
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Ever needed to assign roles to a model, say a User, and build conditional
|
70
|
+
behaviour on top of that? Enter RoleModel -- roles have never been easier! Just
|
71
|
+
declare your roles and you are done. Assigned roles will be stored as a bitmask.
|
95
72
|
email: martin.rehfeld@glnetworks.de
|
96
73
|
executables: []
|
97
|
-
|
98
74
|
extensions: []
|
99
|
-
|
100
|
-
extra_rdoc_files:
|
75
|
+
extra_rdoc_files:
|
101
76
|
- LICENSE
|
102
77
|
- README.rdoc
|
103
|
-
files:
|
78
|
+
files:
|
104
79
|
- .document
|
105
80
|
- .rspec
|
106
81
|
- .travis.yml
|
@@ -120,37 +95,27 @@ files:
|
|
120
95
|
- spec/roles_spec.rb
|
121
96
|
- spec/spec_helper.rb
|
122
97
|
homepage: http://github.com/martinrehfeld/role_model
|
123
|
-
licenses:
|
98
|
+
licenses:
|
124
99
|
- MIT
|
100
|
+
metadata: {}
|
125
101
|
post_install_message:
|
126
102
|
rdoc_options: []
|
127
|
-
|
128
|
-
require_paths:
|
103
|
+
require_paths:
|
129
104
|
- lib
|
130
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
none: false
|
141
|
-
requirements:
|
142
|
-
- - ">="
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
hash: 3
|
145
|
-
segments:
|
146
|
-
- 0
|
147
|
-
version: "0"
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
148
115
|
requirements: []
|
149
|
-
|
150
116
|
rubyforge_project:
|
151
|
-
rubygems_version:
|
117
|
+
rubygems_version: 2.2.2
|
152
118
|
signing_key:
|
153
|
-
specification_version:
|
119
|
+
specification_version: 4
|
154
120
|
summary: Declare, assign and query roles with ease
|
155
121
|
test_files: []
|
156
|
-
|