lockdown 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/lockdown/controller_inspector.rb +2 -116
- data/lib/lockdown/helper.rb +11 -10
- data/lib/lockdown/system.rb +55 -0
- data/lib/lockdown/version.rb +1 -1
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.3.8 2008-05-01
|
2
|
+
* Fixed: corrected class loader to ensure ObjectSpace is used only once
|
3
|
+
|
4
|
+
== 0.3.7 2008-05-01
|
5
|
+
* Fixed: access rights list for permissions. maded modifications to permissions helper as well.
|
6
|
+
|
1
7
|
== 0.3.6 2008-04-30
|
2
8
|
* Fixed: The block in init.rb does not take a parameter. This has been removed from the template.
|
3
9
|
|
@@ -46,7 +46,7 @@ module Lockdown
|
|
46
46
|
# This is admin access
|
47
47
|
#
|
48
48
|
def all_controllers
|
49
|
-
controllers =
|
49
|
+
controllers = Lockdown::System.controller_classes
|
50
50
|
|
51
51
|
controllers.collect do |controller|
|
52
52
|
methods = available_actions(controller)
|
@@ -59,114 +59,16 @@ module Lockdown
|
|
59
59
|
def paths_for(str_sym, *methods)
|
60
60
|
str = str_sym.to_s if str_sym.is_a?(Symbol)
|
61
61
|
if methods.empty?
|
62
|
-
klass =
|
62
|
+
klass = Lockdown::System.fetch_controller_class(str)
|
63
63
|
methods = available_actions(klass)
|
64
64
|
end
|
65
65
|
methods.collect{|meth| ctr_path(str) + "/" + meth.to_s }
|
66
66
|
end
|
67
67
|
|
68
|
-
def get_controller_class(str)
|
69
|
-
load_controller(str)
|
70
|
-
lockdown_const_get(str)
|
71
|
-
end
|
72
|
-
|
73
|
-
def find_all_controller_classes
|
74
|
-
load_all_controllers
|
75
|
-
return ObjectSpace.controller_classes
|
76
|
-
end
|
77
|
-
|
78
|
-
def ObjectSpace.controller_classes
|
79
|
-
subclasses = []
|
80
|
-
self.each_object(Class) do |klass|
|
81
|
-
subclasses << klass if klass.ancestors.include?(Lockdown.controller_parent)
|
82
|
-
end
|
83
|
-
subclasses
|
84
|
-
end
|
85
|
-
|
86
|
-
def load_controller(str)
|
87
|
-
unless lockdown_const_defined?("Application")
|
88
|
-
require(Lockdown.project_root + "/app/controllers/application.rb")
|
89
|
-
end
|
90
|
-
|
91
|
-
unless lockdown_const_defined?(kontroller_class_name(str))
|
92
|
-
require(Lockdown.project_root + "/app/controllers/#{kontroller_file_name(str)}")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def load_all_controllers
|
97
|
-
Dir["#{Lockdown.project_root}/app/controllers/**/*.rb"].sort.each do |c|
|
98
|
-
require(c) unless c == "application.rb"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def lockdown_const_defined?(str)
|
103
|
-
if str.include?("__")
|
104
|
-
# this is a namespaced controller. need to apply const_defined_to the namespace
|
105
|
-
parts = str.split("__")
|
106
|
-
eval("#{camelize(parts[0])}.const_defined?(\"#{kontroller_class_name(parts[1])}\")")
|
107
|
-
else
|
108
|
-
const_defined?(camelize(str))
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def lockdown_const_get(str)
|
113
|
-
if str.include?("__")
|
114
|
-
# this is a namespaced controller. need to apply const_get the namespace
|
115
|
-
parts = str.split("__")
|
116
|
-
eval("#{camelize(parts[0])}.const_get(\"#{kontroller_class_name(parts[1])}\")")
|
117
|
-
else
|
118
|
-
const_get(kontroller_class_name(str))
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
68
|
def ctr_path(str)
|
123
69
|
str.gsub("__","\/")
|
124
70
|
end
|
125
71
|
|
126
|
-
#
|
127
|
-
# Convert the str parameter (originally the symbol) to the
|
128
|
-
# class name.
|
129
|
-
#
|
130
|
-
# For a controller defined as :users in init.rb, the str
|
131
|
-
# parameter here would be "users". The result of this method
|
132
|
-
# would be "/users"
|
133
|
-
#
|
134
|
-
# For a namespaced controller:
|
135
|
-
# In init.rb it would be defined as :admin__users.
|
136
|
-
# The str paramter would be "admin__users".
|
137
|
-
# The result would be "/admin/users".
|
138
|
-
#
|
139
|
-
def controller_file_name(str)
|
140
|
-
if str.include?("__")
|
141
|
-
str.split("__").join("/")
|
142
|
-
else
|
143
|
-
str
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
#
|
148
|
-
# Convert the str parameter (originally the symbol) to the
|
149
|
-
# class name.
|
150
|
-
#
|
151
|
-
# For a controller defined as :users in init.rb, the str
|
152
|
-
# parameter here would be "users". The result of this method
|
153
|
-
# would be "Users"
|
154
|
-
#
|
155
|
-
def controller_class_name(str)
|
156
|
-
if str.include?("__")
|
157
|
-
str.split("__").collect{|p| camelize(p)}.join("::")
|
158
|
-
else
|
159
|
-
camelize(str)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
#
|
164
|
-
# The reverse of controller_class_name. Convert the controllers
|
165
|
-
# class name to the string version of the symbols used in acces.rb.
|
166
|
-
#
|
167
|
-
# For a controller defined as :users in init.rb, the klass
|
168
|
-
# parameter here would be Users (the class). The result of this method
|
169
|
-
# would be "users", the string version of :users.
|
170
72
|
#
|
171
73
|
# Luckily both Rails and Merb have the controller_name method. This
|
172
74
|
# is here in case that changes.
|
@@ -179,14 +81,6 @@ module Lockdown
|
|
179
81
|
module Rails #:nodoc:
|
180
82
|
include Lockdown::ControllerInspector::Core
|
181
83
|
|
182
|
-
def kontroller_class_name(str)
|
183
|
-
"#{controller_class_name(str)}Controller"
|
184
|
-
end
|
185
|
-
|
186
|
-
def kontroller_file_name(str)
|
187
|
-
"#{controller_file_name(str)}_controller.rb"
|
188
|
-
end
|
189
|
-
|
190
84
|
def available_actions(klass)
|
191
85
|
klass.public_instance_methods - klass.hidden_actions
|
192
86
|
end
|
@@ -195,14 +89,6 @@ module Lockdown
|
|
195
89
|
module Merb #:nodoc:
|
196
90
|
include Lockdown::ControllerInspector::Core
|
197
91
|
|
198
|
-
def kontroller_class_name(str)
|
199
|
-
controller_class_name(str)
|
200
|
-
end
|
201
|
-
|
202
|
-
def kontroller_file_name(str)
|
203
|
-
controller_file_name(str) + ".rb"
|
204
|
-
end
|
205
|
-
|
206
92
|
def available_actions(klass)
|
207
93
|
klass.callable_actions.keys
|
208
94
|
end
|
data/lib/lockdown/helper.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
module Lockdown
|
2
2
|
module Helper
|
3
|
-
def syms_from_names(ary)
|
4
|
-
rvalue = []
|
5
|
-
ary.each{|ar| rvalue << symbolize(ar.name)}
|
6
|
-
rvalue
|
7
|
-
end
|
8
|
-
|
9
3
|
#
|
10
4
|
# If str_sym is a Symbol (:users), give me back "Users"
|
11
5
|
# If str_sym is a String ("Users"), give me back :users
|
@@ -28,10 +22,6 @@ module Lockdown
|
|
28
22
|
str_sym.is_a?(String) ? convert_reference_name(str_sym) : str_sym
|
29
23
|
end
|
30
24
|
|
31
|
-
def symbolize(str)
|
32
|
-
str.downcase.gsub("admin ","admin__").gsub(" ","_").to_sym
|
33
|
-
end
|
34
|
-
|
35
25
|
def camelize(str)
|
36
26
|
str.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
37
27
|
end
|
@@ -65,5 +55,16 @@ module Lockdown
|
|
65
55
|
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
66
56
|
tr("-", "_").downcase
|
67
57
|
end
|
58
|
+
|
59
|
+
if Lockdown.rails_app?
|
60
|
+
def kontroller_class_name(str)
|
61
|
+
"#{str}Controller"
|
62
|
+
end
|
63
|
+
else
|
64
|
+
def kontroller_class_name(str)
|
65
|
+
str
|
66
|
+
end
|
67
|
+
end
|
68
68
|
end
|
69
|
+
|
69
70
|
end
|
data/lib/lockdown/system.rb
CHANGED
@@ -17,6 +17,8 @@ module Lockdown
|
|
17
17
|
# :private_access will restrict access to model data to their creators.
|
18
18
|
# attr_accessor :private_access #:nodoc:
|
19
19
|
|
20
|
+
attr_accessor :controller_classes #:nodoc:
|
21
|
+
|
20
22
|
def configure(&block)
|
21
23
|
self.set_defaults
|
22
24
|
self.instance_eval(&block)
|
@@ -177,9 +179,18 @@ module Lockdown
|
|
177
179
|
all_controllers
|
178
180
|
end
|
179
181
|
|
182
|
+
def fetch_controller_class(str)
|
183
|
+
@controller_classes.each do |klass|
|
184
|
+
return klass if klass.name == controller_class_name(str)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
180
188
|
protected
|
181
189
|
|
182
190
|
def set_defaults
|
191
|
+
@controller_classes = []
|
192
|
+
load_controller_classes
|
193
|
+
|
183
194
|
@permissions = {}
|
184
195
|
@user_groups = {}
|
185
196
|
|
@@ -205,6 +216,50 @@ module Lockdown
|
|
205
216
|
false
|
206
217
|
end
|
207
218
|
|
219
|
+
def load_controller_classes
|
220
|
+
unless const_defined?("Application")
|
221
|
+
require(Lockdown.project_root + "/app/controllers/application.rb")
|
222
|
+
end
|
223
|
+
|
224
|
+
Dir.chdir("#{Lockdown.project_root}/app/controllers") do
|
225
|
+
Dir["**/*.rb"].sort.each do |c|
|
226
|
+
next if c == "application.rb"
|
227
|
+
klass = controller_class_name_from_file(c)
|
228
|
+
require(c) unless qualified_const_defined?(klass)
|
229
|
+
@controller_classes.push( qualified_const_get(klass) )
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def controller_class_name_from_file(str)
|
235
|
+
str.split(".")[0].split("/").collect{|str| camelize(str) }.join("::")
|
236
|
+
end
|
237
|
+
|
238
|
+
def controller_class_name(str)
|
239
|
+
if str.include?("__")
|
240
|
+
kontroller_class_name(str.split("__").collect{|p| camelize(p)}.join("::"))
|
241
|
+
else
|
242
|
+
kontroller_class_name(camelize(str))
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def qualified_const_defined?(klass)
|
247
|
+
if klass =~ /::/
|
248
|
+
namespace, klass = klass.split("::")
|
249
|
+
eval("#{namespace}.const_defined?(#{klass})") if const_defined?(namespace)
|
250
|
+
else
|
251
|
+
const_defined?(klass)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def qualified_const_get(klass)
|
256
|
+
if klass =~ /::/
|
257
|
+
namespace, klass = klass.split("::")
|
258
|
+
eval(namespace).const_get(klass)
|
259
|
+
else
|
260
|
+
const_get(klass)
|
261
|
+
end
|
262
|
+
end
|
208
263
|
end # class block
|
209
264
|
end # System class
|
210
265
|
end # Lockdown
|
data/lib/lockdown/version.rb
CHANGED