easy_roles 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,8 +4,15 @@ Simple rails gem for basic role authorization with ruby on rails.
4
4
 
5
5
  == Changelog
6
6
 
7
+ === 03 February 2010 - Version 0.4.2
8
+ Fixed migration names
9
+ Does not allow duplicates to be added
10
+
11
+ === 08 December 2009 - Version 0.4.1
12
+ Added a bitmask migration generator (Read below for usage)
13
+
7
14
  === 08 December 2009 - Version 0.4.0
8
- Added the ability to use bitmasks instead of serializing the roles in a table
15
+ Added the ability to use bitmasks instead of serializing the roles in a table (Read below on how to setup and use)
9
16
 
10
17
  === 17 November 2009 - Version 0.3.0
11
18
  Added a generator to generate the database columns "script/generate easy_roles Table Column_Name"
@@ -47,11 +54,36 @@ Then you need to add "easy_roles :column_name" to your model.
47
54
 
48
55
  === Bitmask Method
49
56
 
57
+ ==== WARNING: If you plan on using the column name 'roles' for the bitmask method your getter and setter actions will be 'easy_roles' and 'easy_roles=', instead of 'roles' and 'roles='. I would suggest using 'roles_mask' as your roles column for this method.
58
+
50
59
  Add the following to your enviroment.rb in the rails initializer block
51
60
 
52
61
  config.gem 'easy_roles', :source => 'http://gemcutter.org'
53
62
 
54
- And thats it.
63
+ (from version 0.4.1) use the migration generator to generate the roles column for your users table
64
+
65
+ E.G. script/generate easy_bitmask_roles user roles_mask
66
+
67
+ Or add a "roles_mask" column to your users model of type 'integer', and set the default value to 0. Please note you can call this column anything you like, I like to use the name "roles_mask".
68
+
69
+ t.integer :roles_mask, :default => 0
70
+
71
+ Add "easy_roles :column_name, :method => :bitmask" to your model.
72
+
73
+ class User < ActiveRecord::Base
74
+ easy_roles :roles_mask, :method => :bitmask
75
+ end
76
+
77
+ And lastly you need to add a constant variable which stores an array of the different roles for your system. The name of the constant must be the name of your column in full caps.
78
+
79
+ ==== WARNING: Bitmask storage relies that you DO NOT change the order of your array of roles, if you need to add a new role, just append it to the end of the array.
80
+
81
+ class User < ActiveRecord::Base
82
+ easy_roles :roles_mask, :method => :bitmask
83
+
84
+ # Constant variable storing roles in the system
85
+ ROLES_MASK = %w[admin moderator user]
86
+ end
55
87
 
56
88
  == Usage
57
89
 
@@ -68,6 +100,10 @@ check to see if a user has a certain role
68
100
  # or
69
101
  is_role? # role being anything you like, for example 'is_admin?' or 'is_awesome?'
70
102
 
103
+ For every method above there is a bang method too.
104
+ add_role! 'role'
105
+ remove_role! 'role'
106
+
71
107
  == Examples
72
108
 
73
109
  @user = User.first
@@ -119,8 +155,12 @@ Then in your AdminsController or any controller that you only want admins to vie
119
155
  class MarksController < ApplicationController
120
156
  before_filter :admin_required, :only => :create, :update
121
157
  end
122
-
123
- check out http://blog.platform45.com/2009/10/05/howto-basic-roles-for-users for implementation, and http://blog.platform45.com/2009/10/07/easy-roles-gem-released for usage.
158
+
159
+ Check out http://blog.platform45.com/2009/10/05/howto-basic-roles-for-users for implementation, and http://blog.platform45.com/2009/10/07/easy-roles-gem-released for usage.
160
+
161
+ Follow me on twitter: http://twitter.com/ryan_za
162
+
163
+ Email: ryan *at* platform45.com
124
164
 
125
165
 
126
166
  == License
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('easy_roles', '0.4.1') do |p|
5
+ Echoe.new('easy_roles', '0.4.2') do |p|
6
6
  p.description = "Easy role authorization in rails"
7
7
  p.url = "http://github.com/platform45/easy_roles"
8
8
  p.author = "Platform45"
data/easy_roles.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{easy_roles}
5
- s.version = "0.4.1"
5
+ s.version = "0.4.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Platform45"]
9
- s.date = %q{2009-12-08}
9
+ s.date = %q{2010-02-03}
10
10
  s.description = %q{Easy role authorization in rails}
11
11
  s.email = %q{ryan@platform45.com}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/easy_roles.rb"]
@@ -2,7 +2,7 @@ class EasyBitmaskRolesGenerator < Rails::Generator::NamedBase
2
2
  def manifest
3
3
  record do |m|
4
4
  m.class_collisions class_name
5
- m.migration_template 'migration.rb', "db/migrate", :migration_file_name => "add_#{args.first}_to_#{table_name}"
5
+ m.migration_template 'migration.rb', "db/migrate", :migration_file_name => "add_bitmask_roles_to_#{table_name}"
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ class EasyRolesGenerator < Rails::Generator::NamedBase
2
2
  def manifest
3
3
  record do |m|
4
4
  m.class_collisions class_name
5
- m.migration_template 'migration.rb', "db/migrate", :migration_file_name => "add_#{args.first}_to_#{table_name}"
5
+ m.migration_template 'migration.rb', "db/migrate", :migration_file_name => "add_roles_to_#{table_name}"
6
6
  end
7
7
  end
8
8
  end
data/lib/easy_roles.rb CHANGED
@@ -19,7 +19,8 @@ module EasyRoles
19
19
  end
20
20
 
21
21
  def add_role(role)
22
- self.#{name} << role
22
+ clear_roles if self.#{name}.nil?
23
+ has_role?(role) ? false : self.#{name} << role
23
24
  end
24
25
 
25
26
  def add_role!(role)
@@ -68,7 +69,7 @@ module EasyRoles
68
69
  end
69
70
 
70
71
  def add_role(role)
71
- new_roles = #{def_name}.push(role)
72
+ new_roles = #{def_name}.push(role).uniq
72
73
  self.#{def_name} = new_roles
73
74
  end
74
75
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_roles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Platform45
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-08 00:00:00 +02:00
12
+ date: 2010-02-03 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15