roles_active_record 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/generators/active_record/roles/roles_generator.rb +2 -3
- data/lib/generators/active_record/roles_migration/roles_migration_generator.rb +16 -2
- data/lib/generators/active_record/roles_migration/templates/add_one_role_strategy.erb +7 -0
- data/roles_active_record.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
@@ -11,7 +11,6 @@ module ActiveRecord
|
|
11
11
|
class_option :strategy, :type => :string, :aliases => "-s", :default => 'role_string',
|
12
12
|
:desc => "Role strategy to use (admin_flag, role_string, roles_string, role_strings, one_role, many_roles, roles_mask)"
|
13
13
|
|
14
|
-
|
15
14
|
class_option :roles, :type => :array, :aliases => "-r", :default => [], :desc => "Valid roles"
|
16
15
|
class_option :default_roles, :type => :boolean, :default => true, :desc => "Use default roles :admin and :base"
|
17
16
|
class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
|
@@ -72,11 +71,11 @@ module ActiveRecord
|
|
72
71
|
end
|
73
72
|
|
74
73
|
def role_class_stmt
|
75
|
-
" role_class :role" if [:one_role, :many_roles].include?
|
74
|
+
" role_class :role" if [:one_role, :many_roles].include?(strategy.to_sym)
|
76
75
|
end
|
77
76
|
|
78
77
|
def insertion_text
|
79
|
-
%Q{include Roles::#{orm.to_s.camelize}
|
78
|
+
%Q{include Roles::#{orm.to_s.camelize}
|
80
79
|
#{role_strategy_statement}
|
81
80
|
#{roles_statement}}
|
82
81
|
end
|
@@ -13,6 +13,8 @@ module ActiveRecord
|
|
13
13
|
class_option :strategy, :type => :string, :aliases => "-s", :default => 'inline_role',
|
14
14
|
:desc => "Role strategy to use (admin_flag, role_string, one_role, many_roles, roles_mask)"
|
15
15
|
|
16
|
+
class_option :roles, :type => :array, :aliases => "-r", :default => [], :desc => "Valid roles"
|
17
|
+
class_option :default_roles, :type => :boolean, :default => true, :desc => "Use default roles :admin and :base"
|
16
18
|
class_option :logfile, :type => :string, :default => nil, :desc => "Logfile location"
|
17
19
|
class_option :reverse, :type => :boolean, :alias => "-r", :default => false, :desc => "Create a remove migration for reversing a strategy"
|
18
20
|
|
@@ -35,17 +37,29 @@ module ActiveRecord
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
40
|
+
def default_roles
|
41
|
+
options[:default_roles] ? [:admin, :guest] : []
|
42
|
+
end
|
43
|
+
|
44
|
+
def roles_to_add
|
45
|
+
@roles_to_add ||= default_roles.concat(options[:roles]).to_symbols.uniq
|
46
|
+
end
|
47
|
+
|
38
48
|
def run_migration
|
39
49
|
logger.debug "Create migration for role_strategy: #{strategy}"
|
40
50
|
migration_name = "add_#{strategy}_strategy"
|
41
51
|
target_migration_name = reverse? ? reverse_migration_name(migration_name) : migration_name
|
42
|
-
migration_template "#{migration_name}.erb", "db/
|
52
|
+
migration_template "#{migration_name}.erb", "db/migrate/#{target_migration_name}"
|
43
53
|
generated_migration = latest_migration_file(migration_dir, target_migration_name)
|
44
54
|
reverse_migration!(generated_migration) if generated_migration && reverse?
|
45
|
-
end
|
55
|
+
end
|
46
56
|
|
47
57
|
include Rails3::Assist::BasicLogger
|
48
58
|
|
59
|
+
def logfile
|
60
|
+
options[:logfile]
|
61
|
+
end
|
62
|
+
|
49
63
|
def strategies
|
50
64
|
[:admin_flag, :role_string, :one_role, :many_roles, :roles_mask]
|
51
65
|
end
|
@@ -4,6 +4,7 @@ class AddOneRoleStrategy < ActiveRecord::Migration
|
|
4
4
|
def up
|
5
5
|
create_roles
|
6
6
|
add_user_role
|
7
|
+
insert_roles
|
7
8
|
end
|
8
9
|
|
9
10
|
def down
|
@@ -36,5 +37,11 @@ class AddOneRoleStrategy < ActiveRecord::Migration
|
|
36
37
|
def drop_roles
|
37
38
|
drop_table :roles
|
38
39
|
end
|
40
|
+
|
41
|
+
def insert_roles
|
42
|
+
<%- roles_to_add.each do |role| -%>
|
43
|
+
Role.create!(:name => '<%= role %>')
|
44
|
+
<%- end -%>
|
45
|
+
end
|
39
46
|
end
|
40
47
|
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.3.
|
8
|
+
s.version = "0.3.3"
|
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{2010-12-
|
12
|
+
s.date = %q{2010-12-17}
|
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 = [
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 3
|
9
|
+
version: 0.3.3
|
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: 2010-12-
|
17
|
+
date: 2010-12-17 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|