rolify 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +7 -0
- data/README.rdoc +2 -4
- data/lib/rolify/role.rb +11 -2
- data/lib/rolify/version.rb +1 -1
- data/spec/rolify/role_spec.rb +10 -0
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
= 0.7
|
2
|
+
* added a method_missing to catch newly created role outside the current ruby process (i.e. dynamic shortcut methods are not defined within this process)
|
3
|
+
* dynamic shortcut is created on the fly in the method_missing to avoid extra method_missing for the same dynamic shortcut
|
4
|
+
* check if the role actually exists in the database before defining the new method
|
5
|
+
* first call is slower due to method_missing but next calls are fast
|
6
|
+
* avoid strange bugs when spawning many ruby processes as the dynamic shortcut methods were only defined in the process that used the <tt>has_role</tt> command
|
7
|
+
|
1
8
|
= 0.6
|
2
9
|
* custom User and Role class names support
|
3
10
|
* can now use other class names for Role and User classes
|
data/README.rdoc
CHANGED
@@ -11,7 +11,7 @@ This library was intended to be used with CanCan[https://github.com/ryanb/cancan
|
|
11
11
|
|
12
12
|
== Requirements
|
13
13
|
|
14
|
-
* >= Rails 3.1 (
|
14
|
+
* >= Rails 3.1 (rc4 is currently out)
|
15
15
|
* ActiveRecord ORM
|
16
16
|
|
17
17
|
== Installation
|
@@ -34,7 +34,6 @@ First, create your Role model and migration file using this generator:
|
|
34
34
|
|
35
35
|
Role and User classes are the default. You can specify any Role class name you want. This is completly a new file so any name can do the job.
|
36
36
|
For the User class name, you would probably use the one provided by your authentication solution. rolify just adds some class methods in an existing User class.
|
37
|
-
<b>**For now, please stick to Role and User class names, see {#5}[https://github.com/EppO/rolify/issues/5] for details**</b>
|
38
37
|
|
39
38
|
=== 2. Run the migration
|
40
39
|
|
@@ -83,7 +82,7 @@ A global role overrides resource role request:
|
|
83
82
|
user.has_role? "moderator", Forum.last
|
84
83
|
=> true
|
85
84
|
|
86
|
-
Please see on {the wiki}[https://github.com/EppO/rolify/wiki/Usage] for all the available commands
|
85
|
+
Please see on {the wiki}[https://github.com/EppO/rolify/wiki/Usage] for all the available commands and the {Tutorial}[https://github.com/EppO/rolify/wiki/Tutorial] to understand how to use {rolify}[http://eppo.github.com/rolify] with {Devise}[https://github.com/plataformatec/devise] and {CanCan}[https://github.com/ryanb/cancan].
|
87
86
|
|
88
87
|
== Questions or Problems?
|
89
88
|
|
@@ -91,6 +90,5 @@ If you have any issue or feature request with/for rolify, please add an {issue o
|
|
91
90
|
|
92
91
|
== TODO
|
93
92
|
|
94
|
-
* write a tutorial showing how to use rolify with CanCan and devise
|
95
93
|
* complete tests coverage
|
96
94
|
* performance enhancements
|
data/lib/rolify/role.rb
CHANGED
@@ -76,6 +76,16 @@ module Rolify
|
|
76
76
|
def roles_name
|
77
77
|
self.roles.select(:name).map { |r| r.name }
|
78
78
|
end
|
79
|
+
|
80
|
+
def method_missing(method, *args, &block)
|
81
|
+
if method.to_s.match(/^is_(\w+)_of[?]$/) || method.to_s.match(/^is_(\w+)[?]$/)
|
82
|
+
if Rolify.role_cname.where(:name => $1).count > 0
|
83
|
+
resource = args.first
|
84
|
+
self.class.define_dynamic_method $1, resource
|
85
|
+
has_role?("#{$1}", resource)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
79
89
|
|
80
90
|
private
|
81
91
|
|
@@ -111,7 +121,6 @@ module Rolify
|
|
111
121
|
has_role?("#{role_name}", arg)
|
112
122
|
end if !method_defined?("is_#{role_name}_of?".to_sym) && resource
|
113
123
|
end
|
114
|
-
end
|
115
|
-
|
124
|
+
end
|
116
125
|
end
|
117
126
|
end
|
data/lib/rolify/version.rb
CHANGED
data/spec/rolify/role_spec.rb
CHANGED
@@ -43,6 +43,16 @@ shared_examples_for "Rolify module" do
|
|
43
43
|
it "should not respond to any unknown methods" do
|
44
44
|
@admin.should_not respond_to(:is_god?)
|
45
45
|
end
|
46
|
+
|
47
|
+
it "should create a new dynamic method if role exists in database" do
|
48
|
+
Rolify.role_cname.create(:name => "superman")
|
49
|
+
@admin.is_superman?.should be(false)
|
50
|
+
@admin.should respond_to(:is_superman?).with(0).arguments
|
51
|
+
Rolify.role_cname.create(:name => "batman", :resource => Forum.first)
|
52
|
+
@admin.is_batman_of?(Forum.first).should be(false)
|
53
|
+
@admin.should respond_to(:is_batman_of?).with(1).arguments
|
54
|
+
@admin.should respond_to(:is_batman?).with(0).arguments
|
55
|
+
end
|
46
56
|
end
|
47
57
|
|
48
58
|
context "with a global role" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rolify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.7.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Florent Monbillard
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-21 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sqlite3
|