roles_active_record 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
@@ -26,12 +26,12 @@ module ActiveRecord
|
|
26
26
|
logger.debug "apply_role_strategy for : #{strategy} in model #{name}"
|
27
27
|
|
28
28
|
if !valid_strategy?
|
29
|
-
say "Strategy '#{strategy}' is not valid, at least not for Active Record"
|
29
|
+
say "Strategy '#{strategy}' is not valid, at least not for Active Record", :red
|
30
30
|
return
|
31
31
|
end
|
32
32
|
|
33
33
|
if !has_model? :user
|
34
|
-
say "Could not apply roles strategy to #{name} model since the model file was not found"
|
34
|
+
say "Could not apply roles strategy to #{name} model since the model file was not found", :red
|
35
35
|
return
|
36
36
|
end
|
37
37
|
|
@@ -50,7 +50,9 @@ module ActiveRecord
|
|
50
50
|
protected
|
51
51
|
|
52
52
|
extend Rails3::Assist::UseMacro
|
53
|
+
|
53
54
|
use_orm :active_record
|
55
|
+
|
54
56
|
include Rails3::Assist::BasicLogger
|
55
57
|
|
56
58
|
def copy_role_models
|
@@ -4,7 +4,9 @@ module Roles::Base
|
|
4
4
|
end
|
5
5
|
end
|
6
6
|
|
7
|
-
module Roles::ActiveRecord
|
7
|
+
module Roles::ActiveRecord
|
8
|
+
mattr_accessor :warnings_on
|
9
|
+
|
8
10
|
def self.included(base)
|
9
11
|
base.extend Roles::Base
|
10
12
|
base.extend ClassMethods
|
@@ -38,24 +40,37 @@ module Roles::ActiveRecord
|
|
38
40
|
|
39
41
|
# one_role reference
|
40
42
|
if strategy_name == :one_role
|
41
|
-
self.belongs_to :one_role, :foreign_key => 'role_id', :class_name =>
|
43
|
+
self.belongs_to :one_role, :foreign_key => 'role_id', :class_name => role_class_name.to_s
|
42
44
|
end
|
43
45
|
|
44
46
|
# many_roles references
|
45
|
-
if strategy_name == :many_roles
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
instance_eval %{
|
50
|
-
has_many :many_roles, :through => :#{user_roles_class}, :source => :#{@role_class_name.to_s.underscore}
|
51
|
-
has_many :#{user_roles_class}
|
52
|
-
}
|
47
|
+
if strategy_name == :many_roles
|
48
|
+
urc = user_roles_class options
|
49
|
+
instance_eval many_roles_stmt(urc)
|
53
50
|
end
|
54
51
|
|
55
52
|
set_role_strategy name, options
|
56
53
|
end
|
57
54
|
|
58
55
|
private
|
56
|
+
|
57
|
+
def many_roles_stmt urc
|
58
|
+
%{
|
59
|
+
has_many :many_roles, :through => :#{urc}, :source => :#{role_class_name.to_s.underscore}
|
60
|
+
has_many :#{urc}
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def role_class_name options = {}
|
65
|
+
return @role_class_name if @role_class_name
|
66
|
+
return options[:role_class] if options.kind_of?(Hash) && options[:role_class]
|
67
|
+
'Role'
|
68
|
+
end
|
69
|
+
|
70
|
+
def user_roles_class options
|
71
|
+
return options[:user_roles_class] if options.kind_of?(Hash) && options[:user_roles_class]
|
72
|
+
'user_roles'
|
73
|
+
end
|
59
74
|
|
60
75
|
def set_role_class strategy_name, options = {}
|
61
76
|
@role_class_name = !options.kind_of?(Symbol) ? get_role_class(strategy_name, options) : default_role_class(strategy_name)
|
@@ -70,7 +85,7 @@ module Roles::ActiveRecord
|
|
70
85
|
require "roles_active_record/#{strategy_name}"
|
71
86
|
return ::Role
|
72
87
|
end
|
73
|
-
raise "Default Role class not defined"
|
88
|
+
raise "Default Role class not defined" if Roles::ActiveRecord.warnings_on
|
74
89
|
end
|
75
90
|
|
76
91
|
def get_role_class strategy_name, options
|
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.4"
|
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-04}
|
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
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 4
|
9
|
+
version: 0.4.4
|
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-04 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|