rolify 3.3.0.rc1 → 3.3.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
data/lib/rolify/configure.rb
CHANGED
@@ -3,7 +3,8 @@ module Rolify
|
|
3
3
|
@@dynamic_shortcuts = false
|
4
4
|
@@orm = "active_record"
|
5
5
|
|
6
|
-
def configure
|
6
|
+
def configure(*role_cnames)
|
7
|
+
return if !sanity_check(role_cnames)
|
7
8
|
yield self if block_given?
|
8
9
|
end
|
9
10
|
|
@@ -37,5 +38,19 @@ module Rolify
|
|
37
38
|
config.orm = "active_record"
|
38
39
|
end
|
39
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def sanity_check(role_cnames)
|
45
|
+
role_cnames = [ "Role" ] if role_cnames.empty?
|
46
|
+
role_cnames.each do |role_cname|
|
47
|
+
role_class = role_cname.constantize
|
48
|
+
if role_class.superclass == ActiveRecord && !role_class.table_exists?
|
49
|
+
warn "[WARN] table '#{role_cname}' doesn't exist. Did you run the migration ? Ignoring rolify config."
|
50
|
+
return false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
true
|
54
|
+
end
|
40
55
|
end
|
41
56
|
end
|
data/lib/rolify/resource.rb
CHANGED
@@ -8,11 +8,16 @@ module Rolify
|
|
8
8
|
def find_roles(role_name = nil, user = nil)
|
9
9
|
roles = user && (user != :any) ? user.roles : self.role_class
|
10
10
|
roles = roles.where(:resource_type => self.to_s)
|
11
|
-
roles = roles.where(:name => role_name) if role_name && (role_name != :any)
|
11
|
+
roles = roles.where(:name => role_name.to_s) if role_name && (role_name != :any)
|
12
12
|
roles
|
13
13
|
end
|
14
14
|
|
15
15
|
def with_role(role_name, user = nil)
|
16
|
+
if role_name.is_a? Array
|
17
|
+
role_name.map!(&:to_s)
|
18
|
+
else
|
19
|
+
role_name = role_name.to_s
|
20
|
+
end
|
16
21
|
resources = self.adapter.resources_find(self.role_table_name, self, role_name)
|
17
22
|
user ? self.adapter.in(resources, user, role_name) : resources
|
18
23
|
end
|
data/lib/rolify/role.rb
CHANGED
@@ -52,7 +52,7 @@ module Rolify
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def remove_role(role_name, resource = nil)
|
55
|
-
self.class.adapter.remove(self, role_name, resource)
|
55
|
+
self.class.adapter.remove(self, role_name.to_s, resource)
|
56
56
|
end
|
57
57
|
|
58
58
|
alias_method :revoke, :remove_role
|
@@ -84,4 +84,4 @@ module Rolify
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
87
|
-
end
|
87
|
+
end
|
data/lib/rolify/version.rb
CHANGED
data/rolify.gemspec
CHANGED
@@ -74,7 +74,7 @@ describe Rolify::Generators::RoleGenerator do
|
|
74
74
|
subject { file('config/initializers/rolify.rb') }
|
75
75
|
|
76
76
|
it { should exist }
|
77
|
-
it { should contain "Rolify.configure do |config|"}
|
77
|
+
it { should contain "Rolify.configure(\"AdminRole\") do |config|"}
|
78
78
|
it { should contain "# config.use_dynamic_shortcuts" }
|
79
79
|
it { should contain "# config.use_mongoid" }
|
80
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rolify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.0.
|
4
|
+
version: 3.3.0.rc2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|
@@ -171,6 +171,22 @@ dependencies:
|
|
171
171
|
- - ! '>='
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: fuubar
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ! '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
174
190
|
description: Very simple Roles library without any authorization enforcement supporting
|
175
191
|
scope on resource objects (instance or class). Supports ActiveRecord and Mongoid
|
176
192
|
ORMs.
|