darkhelmet-role_on 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO +1 -0
- data/VERSION +1 -1
- data/lib/role_on.rb +17 -5
- data/role_on.gemspec +2 -1
- metadata +2 -1
data/TODO
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* class methods on user to add helper methods for finding admins, etc
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/role_on.rb
CHANGED
@@ -20,16 +20,28 @@ module RoleOn
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
module
|
24
|
-
def has_role?(
|
25
|
-
return false if roles.
|
26
|
-
roles.include?(Role[
|
23
|
+
module RoleOnUserInstanceMethods
|
24
|
+
def has_role?(*roles)
|
25
|
+
return false if self.roles.empty?
|
26
|
+
roles.reject { |r| self.roles.include?(Role[r]) }.empty?
|
27
|
+
end
|
28
|
+
alias :has_roles? :has_role?
|
29
|
+
end
|
30
|
+
|
31
|
+
module RoleOnUserClassMethods
|
32
|
+
def helper_for(role,name = role.to_s.pluralize)
|
33
|
+
(class << self; self; end).class_eval do
|
34
|
+
define_method("all_#{name}") do
|
35
|
+
User.find(:all, :conditions => [ 'roles.id is ? or roles.id != ?', nil, Role[role].id ], :include => :roles)
|
36
|
+
end
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
29
40
|
|
30
41
|
def self.included(klass)
|
31
42
|
if User == klass
|
32
|
-
klass.send(:include,
|
43
|
+
klass.send(:include, RoleOnUserInstanceMethods)
|
44
|
+
klass.send(:extend, RoleOnUserClassMethods)
|
33
45
|
klass.send(:has_and_belongs_to_many, :roles, :join_table => 'user_roles')
|
34
46
|
elsif ApplicationController == klass
|
35
47
|
klass.send(:extend, RoleOnControllerMethods)
|
data/role_on.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{role_on}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Daniel Huckstep"]
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
"LICENSE",
|
19
19
|
"README.md",
|
20
20
|
"Rakefile",
|
21
|
+
"TODO",
|
21
22
|
"VERSION",
|
22
23
|
"generators/role_on/role_on_generator.rb",
|
23
24
|
"generators/role_on/templates/app/models/role.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: darkhelmet-role_on
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Huckstep
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- LICENSE
|
29
29
|
- README.md
|
30
30
|
- Rakefile
|
31
|
+
- TODO
|
31
32
|
- VERSION
|
32
33
|
- generators/role_on/role_on_generator.rb
|
33
34
|
- generators/role_on/templates/app/models/role.rb
|