roles 0.0.1 → 0.0.2

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/CHANGELOG.rdoc CHANGED
@@ -1,2 +1,5 @@
1
- = v0.1 (Aug 17, 2012)
1
+ = v0.0.2 (Aug 19, 2012)
2
+ * rename `user.resources` to `user.resources_with_role`
3
+
4
+ = v0.0.1 (Aug 17, 2012)
2
5
  * first release
data/README.md CHANGED
@@ -1,9 +1,15 @@
1
1
  # Roles
2
2
 
3
- Roles is an extremely simple roles gem inspired by rolify.
3
+ Roles is an extremely simple roles gem inspired by [rolify](https://github.com/EppO/rolify).
4
4
 
5
5
  This library is recommended to be used with [CanCan](https://github.com/ryanb/cancan) and [devise](https://github.com/plataformatec/devise).
6
6
 
7
+ ## Why Roles
8
+
9
+ Look at this discussion: [comment](https://github.com/EppO/rolify/issues/80#issuecomment-7790341)
10
+
11
+ In a word, Rolify uses two tables `roles` and `users_roles` while Roles only uses one table `roles`.
12
+
7
13
  ## Quick Start
8
14
 
9
15
  ```ruby
@@ -12,6 +18,7 @@ This library is recommended to be used with [CanCan](https://github.com/ryanb/ca
12
18
  user.has_role?(:admin) # if user is admin globally
13
19
  user.has_role?(:admin, Organization) # if user is admin for Organization type
14
20
  user.has_role?(:admin, Organization.first) # if user is not admin of the first organization
21
+ user.role_names(instance = nil) # => returns role names of current user, optionally scoped by Class, instance or non-scoped(globally)
15
22
 
16
23
  # grant roles
17
24
  user.add_role(:admin) # a global admin
@@ -32,20 +39,20 @@ user.has_role? :moderator, Forum.first # => false
32
39
  user.has_role? :moderator, Forum.last # => false
33
40
 
34
41
  # query about users
35
- Forum.users_with_role(role = nil) => returns all users with roles defined on Forum
36
- forum.users_with_role => returns users with a role defined of current instance
37
- User.with_role(role, resource = nil) => returns all users with the given role, optionally scoped by Class, instance or non-scoped(globally)
42
+ Forum.users_with_role(role = nil) # => returns all users with roles defined on Forum
43
+ forum.users_with_role(role = nil) # => returns users with a role defined of current instance
44
+ User.with_role(role, resource = nil) # => returns all users with the given role, optionally scoped by Class, instance or non-scoped(globally)
38
45
 
39
46
  # query about resources
40
- user.resouces(resource_class, :role_name = nil) => returns all resources of type resource_class for a given user, optionally filtered by role_name.
41
-
47
+ user.resources_with_role(Project, role_name = nil)
48
+ # => returns all projects for a given user, optionally filtered by role_name.
42
49
  ```
43
50
 
44
51
  ## Requirements
45
52
 
46
53
  * Rails >= 3.1
47
54
  * ActiveRecord >= 3.1
48
- * supports ruby 1.9, JRuby 1.6.0+ (in 1.9 mode) and Rubinius 2.0.0dev (in 1.9 mode)
55
+ * supports ruby 1.9
49
56
 
50
57
  ## Installation
51
58
 
@@ -62,12 +69,10 @@ Add this to your Gemfile and run the +bundle+ command.
62
69
  First, create your Role model and migration file using this generator:
63
70
 
64
71
  ```
65
- rails g rolify:role Role User
72
+ rails g roles:role Role User
66
73
  ```
67
74
 
68
- 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.
69
- 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.
70
-
75
+ Role and User classes are the default.
71
76
 
72
77
  ### 2. Run the migration
73
78
 
@@ -99,5 +104,6 @@ end
99
104
  ## Resources
100
105
 
101
106
  * [Rolify](https://github.com/EppO/rolify)
107
+ * [CanCan](https://github.com/ryanb/cancan)
102
108
  * [Amazing tutorial](http://railsapps.github.com/tutorial-rails-bootstrap-devise-cancan.html) provided by [RailsApps](http://railsapps.github.com/)
103
109
 
data/lib/roles/railtie.rb CHANGED
@@ -7,14 +7,6 @@ module Rolies
7
7
  ActiveSupport.on_load(:active_record) do
8
8
  ActiveRecord::Base.send :extend, Roles
9
9
  end
10
-
11
- config.before_initialize do
12
- ::Mongoid::Document.module_eval do
13
- def self.included(base)
14
- base.extend Roles
15
- end
16
- end
17
- end if defined?(Mongoid)
18
10
  end
19
11
  end
20
12
  end
data/lib/roles/role.rb CHANGED
@@ -63,7 +63,7 @@ module Roles
63
63
  end
64
64
  end
65
65
 
66
- def resources(resource_class, role_name = nil)
66
+ def resources_with_role(resource_class, role_name = nil)
67
67
  if role_name.nil?
68
68
  resource_class.joins(:roles).where("roles.#{self.class.user_cname.underscore.singularize}_id = %s", self.id).where("roles.resource_type LIKE '%s'", resource_class.to_s)
69
69
  else
data/lib/roles/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Roles
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
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: 2012-08-17 00:00:00.000000000 Z
12
+ date: 2012-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3