roles_active_record 0.4.4 → 0.4.5
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/NOTES.textile +28 -0
- data/VERSION +1 -1
- data/lib/generators/active_record/roles/core_ext.rb +14 -0
- data/lib/generators/active_record/roles/roles_generator.rb +16 -23
- data/roles_active_record.gemspec +4 -2
- metadata +5 -3
data/NOTES.textile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
h1. Alternative Multi Roles setup
|
|
2
|
+
|
|
3
|
+
<pre>
|
|
4
|
+
class UsersHaveAndBelongToManyRoles < ActiveRecord::Migration
|
|
5
|
+
def self.up
|
|
6
|
+
create_table :roles_users, :id => false do |t|
|
|
7
|
+
t.references :role, :user
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.down
|
|
12
|
+
drop_table :roles_users
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
</pre>
|
|
16
|
+
|
|
17
|
+
And your models look like this:
|
|
18
|
+
|
|
19
|
+
<pre>
|
|
20
|
+
# User Model
|
|
21
|
+
class User < ActiveRecord::Base
|
|
22
|
+
has_and_belongs_to_many :roles
|
|
23
|
+
....
|
|
24
|
+
# Role model
|
|
25
|
+
class Role < ActiveRecord::Base
|
|
26
|
+
has_and_belongs_to_many :users
|
|
27
|
+
end
|
|
28
|
+
</pre>
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.4.
|
|
1
|
+
0.4.5
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# TODO:
|
|
2
|
+
# model_file_name and similar methods in rails3_assist and rails3_artifaftor should be fixed to always call underscore on filenames
|
|
3
|
+
|
|
4
|
+
class String
|
|
5
|
+
def as_filename
|
|
6
|
+
self.underscore
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class Symbol
|
|
11
|
+
def as_filename
|
|
12
|
+
self.to_s.underscore
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -1,49 +1,50 @@
|
|
|
1
1
|
require 'rails3_artifactor'
|
|
2
2
|
require 'logging_assist'
|
|
3
|
+
require 'generators/active_record/roles/core_ext'
|
|
3
4
|
|
|
4
5
|
module ActiveRecord
|
|
5
6
|
module Generators
|
|
6
7
|
class RolesGenerator < Rails::Generators::NamedBase
|
|
7
|
-
desc "Add role strategy to a model"
|
|
8
|
+
desc "Add role strategy to a User model"
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
argument :user_class, :type => :string, :default => 'User', :desc => "User class name"
|
|
10
11
|
|
|
11
|
-
class_option :strategy,
|
|
12
|
+
class_option :strategy, :type => :string, :aliases => "-s", :default => 'role_string',
|
|
12
13
|
:desc => "Role strategy to use (admin_flag, role_string, one_role, many_roles, roles_mask)"
|
|
13
14
|
|
|
14
|
-
class_option :roles,
|
|
15
|
-
class_option :role_class,
|
|
16
|
-
class_option :
|
|
17
|
-
class_option :user_role_class, :type => :string, :aliases => "-urc", :default => 'UserRole', :desc => "User Role join class"
|
|
15
|
+
class_option :roles, :type => :array, :aliases => "-r", :default => [], :desc => "Valid roles"
|
|
16
|
+
class_option :role_class, :type => :string, :aliases => "-rc", :default => 'Role', :desc => "Role class"
|
|
17
|
+
class_option :user_role_class, :type => :string, :aliases => "-urc", :default => 'UserRole', :desc => "User Role join class"
|
|
18
18
|
|
|
19
|
-
class_option :default_roles,
|
|
20
|
-
class_option :logfile,
|
|
19
|
+
class_option :default_roles, :type => :boolean, :aliases => "-dr", :default => true, :desc => "Use default roles :admin and :base"
|
|
20
|
+
class_option :logfile, :type => :string, :aliases => "-l", :default => nil, :desc => "Logfile location"
|
|
21
21
|
|
|
22
22
|
source_root File.dirname(__FILE__) + '/templates'
|
|
23
23
|
|
|
24
24
|
def apply_role_strategy
|
|
25
25
|
logger.add_logfile :logfile => logfile if logfile
|
|
26
|
-
logger.debug "apply_role_strategy for : #{strategy} in model #{
|
|
26
|
+
logger.debug "apply_role_strategy for : #{strategy} in model #{user_class}"
|
|
27
27
|
|
|
28
28
|
if !valid_strategy?
|
|
29
29
|
say "Strategy '#{strategy}' is not valid, at least not for Active Record", :red
|
|
30
30
|
return
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
if !has_model?
|
|
34
|
-
say "Could not apply roles strategy to #{
|
|
33
|
+
if !has_model? user_class
|
|
34
|
+
say "Could not apply roles strategy to #{user_class} model since the model file was not found", :red
|
|
35
35
|
return
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
begin
|
|
39
|
-
|
|
38
|
+
begin
|
|
39
|
+
logger.debug "Trying to insert roles code into #{user_class}"
|
|
40
|
+
insert_into_model name.as_filename do
|
|
40
41
|
insertion_text
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
copy_role_models if roles_model_strategy?
|
|
44
45
|
rescue
|
|
45
46
|
# logger.debug "Error applying roles strategy to #{name}"
|
|
46
|
-
say "Error applying roles strategy to #{
|
|
47
|
+
say "Error applying roles strategy to #{user_class}"
|
|
47
48
|
end
|
|
48
49
|
end
|
|
49
50
|
|
|
@@ -90,10 +91,6 @@ module ActiveRecord
|
|
|
90
91
|
[:one_role, :many_roles].include? strategy.to_sym
|
|
91
92
|
end
|
|
92
93
|
|
|
93
|
-
def user_class
|
|
94
|
-
options[:user_class].classify || 'User'
|
|
95
|
-
end
|
|
96
|
-
|
|
97
94
|
def role_class
|
|
98
95
|
options[:role_class].classify || 'Role'
|
|
99
96
|
end
|
|
@@ -106,10 +103,6 @@ module ActiveRecord
|
|
|
106
103
|
options[:logfile]
|
|
107
104
|
end
|
|
108
105
|
|
|
109
|
-
def user_class
|
|
110
|
-
name || 'User'
|
|
111
|
-
end
|
|
112
|
-
|
|
113
106
|
def orm
|
|
114
107
|
:active_record
|
|
115
108
|
end
|
data/roles_active_record.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{roles_active_record}
|
|
8
|
-
s.version = "0.4.
|
|
8
|
+
s.version = "0.4.5"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
|
12
|
-
s.date = %q{2011-01-
|
|
12
|
+
s.date = %q{2011-01-09}
|
|
13
13
|
s.description = %q{Makes it easy to set a role strategy on your User model in Active Record}
|
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -21,11 +21,13 @@ Gem::Specification.new do |s|
|
|
|
21
21
|
".rspec",
|
|
22
22
|
"Gemfile",
|
|
23
23
|
"LICENSE",
|
|
24
|
+
"NOTES.textile",
|
|
24
25
|
"README.textile",
|
|
25
26
|
"Rakefile",
|
|
26
27
|
"VERSION",
|
|
27
28
|
"config/database.yml",
|
|
28
29
|
"development.sqlite3",
|
|
30
|
+
"lib/generators/active_record/roles/core_ext.rb",
|
|
29
31
|
"lib/generators/active_record/roles/roles_generator.rb",
|
|
30
32
|
"lib/generators/active_record/roles/templates/many_roles/role.rb",
|
|
31
33
|
"lib/generators/active_record/roles/templates/many_roles/user_role.rb",
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 4
|
|
8
|
-
-
|
|
9
|
-
version: 0.4.
|
|
8
|
+
- 5
|
|
9
|
+
version: 0.4.5
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Kristian Mandrup
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2011-01-
|
|
17
|
+
date: 2011-01-09 00:00:00 +01:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
@@ -343,11 +343,13 @@ files:
|
|
|
343
343
|
- .rspec
|
|
344
344
|
- Gemfile
|
|
345
345
|
- LICENSE
|
|
346
|
+
- NOTES.textile
|
|
346
347
|
- README.textile
|
|
347
348
|
- Rakefile
|
|
348
349
|
- VERSION
|
|
349
350
|
- config/database.yml
|
|
350
351
|
- development.sqlite3
|
|
352
|
+
- lib/generators/active_record/roles/core_ext.rb
|
|
351
353
|
- lib/generators/active_record/roles/roles_generator.rb
|
|
352
354
|
- lib/generators/active_record/roles/templates/many_roles/role.rb
|
|
353
355
|
- lib/generators/active_record/roles/templates/many_roles/user_role.rb
|