roled 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 create_aro
18
- Aro.new(:foreign_id => self.id, :model => model_name).save
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
@@ -1,3 +1,3 @@
1
1
  module Roled
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -26,46 +26,43 @@ namespace :acos do
26
26
  create_action(controller, action)
27
27
  end
28
28
  end
29
-
30
- puts "All done! :)"
31
- #
32
- # dir = Rails.root.join('app', 'controllers').to_s
33
- #
34
- # @controllers = Dir.entries(dir)
35
- # @actions = Roled::Aco.all
36
- #
37
- # if(@actions.blank?)
38
- # Roled::Aco.new(:name => "roled_root").save
39
- # puts "New install, preparing table..."
40
- # end
41
- #
42
- # @controllers.each do |name|
43
- # if name=~ /^(?!application).*_controller.rb/
44
- #
45
- # controller = File.read(dir + '/' + name)
46
- # name = name.gsub('_controller.rb', "")
47
- # create_action(name, nil)
48
- #
49
- # lines = controller.split(/\r?\n/)
50
- # lines.each do |l|
51
- # if l.strip =~ /(\Aprotected\z|\Aprivate\z)/
52
- # break
53
- # end
54
- # if l.strip =~ /\Adef \w*/
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 + "_controller"
59
+ controller_name = "#{controller}_controller"
67
60
  if(!Roled::Aco.where(:action => action, :parent => controller_name).exists?)
68
- puts "Saving action: " + action + " for controller: " + controller
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roled
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: