roled 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/roled/acts_as.rb +14 -11
- data/lib/roled/version.rb +1 -1
- data/lib/tasks/acos.rake +32 -35
- metadata +1 -1
data/lib/roled/acts_as.rb
CHANGED
@@ -3,19 +3,10 @@ module Roled
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def model_name
|
10
|
-
self.class.name.sub("Controller", "").singularize
|
11
|
-
end
|
12
|
-
|
13
|
-
def current_aro
|
14
|
-
Aro.where(:model => model_name, :foreign_id => self.id).first
|
15
6
|
end
|
16
7
|
|
17
|
-
def
|
18
|
-
|
8
|
+
def permission?(controller, action)
|
9
|
+
return has_permission_to?(controller,action)
|
19
10
|
end
|
20
11
|
|
21
12
|
def has_permission_to?(controller, action)
|
@@ -109,6 +100,18 @@ module Roled
|
|
109
100
|
end
|
110
101
|
end
|
111
102
|
|
103
|
+
def current_aro
|
104
|
+
Aro.where(:model => model_name, :foreign_id => self.id).first
|
105
|
+
end
|
106
|
+
|
107
|
+
def create_aro
|
108
|
+
Aro.new(:foreign_id => self.id, :model => model_name).save
|
109
|
+
end
|
110
|
+
|
111
|
+
def model_name
|
112
|
+
self.class.name.sub("Controller", "").singularize
|
113
|
+
end
|
114
|
+
|
112
115
|
module ClassMethods
|
113
116
|
def acts_as_aro(options = {})
|
114
117
|
class_eval do
|
data/lib/roled/version.rb
CHANGED
data/lib/tasks/acos.rake
CHANGED
@@ -26,46 +26,43 @@ namespace :acos do
|
|
26
26
|
create_action(controller, action)
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# create_action(l.gsub('def','').strip!, name)
|
56
|
-
# end
|
57
|
-
# end
|
58
|
-
# end
|
59
|
-
# end
|
60
|
-
# puts "All Done... :)"
|
29
|
+
|
30
|
+
dir = Rails.root.join('app', 'controllers').to_s
|
31
|
+
|
32
|
+
@controllers = Dir.entries(dir)
|
33
|
+
@actions = Roled::Aco.all
|
34
|
+
|
35
|
+
@controllers.each do |name|
|
36
|
+
if name=~ /^(?!application).*_controller.rb/
|
37
|
+
controller = File.read(dir + '/' + name)
|
38
|
+
name = name.gsub('_controller.rb', "")
|
39
|
+
create_action(name)
|
40
|
+
|
41
|
+
lines = controller.split(/\r?\n/)
|
42
|
+
ignore = false
|
43
|
+
lines.each do |l|
|
44
|
+
if l.strip =~ /(\Aprotected\z|\Aprivate\z)/ && !ignore
|
45
|
+
ignore = true
|
46
|
+
elsif l.strip == "public" && ignore
|
47
|
+
ignore = false
|
48
|
+
elsif l.strip =~ /\Adef \w*/ && !ignore
|
49
|
+
create_action(name, l.gsub('def','').strip!)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
puts "All done! :)"
|
61
55
|
end
|
62
56
|
end
|
63
57
|
|
64
|
-
|
65
58
|
def create_action(controller = nil, action = nil)
|
66
|
-
controller_name = controller
|
59
|
+
controller_name = "#{controller}_controller"
|
67
60
|
if(!Roled::Aco.where(:action => action, :parent => controller_name).exists?)
|
68
|
-
|
61
|
+
if(action.blank?)
|
62
|
+
puts "Saving controller: #{controller} "
|
63
|
+
else
|
64
|
+
puts "Saving action: #{controller}##{action} "
|
65
|
+
end
|
69
66
|
Roled::Aco.new(:action => action, :parent => controller_name).save
|
70
67
|
end
|
71
68
|
|