mistiq 0.0.925 → 0.0.926
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/mistiq/defaults.rb +1 -1
- data/lib/mistiq/init.rb +181 -161
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWE1YjgyZTBkYzRhYjA0ZDc1YWIzYzNlM2VlMzBmMTM1MmQ2ZTZiNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzFkYTcxYTcwMGI0NjM2MTI1ZmUyZDIzYTJjYmQyZjYzMmZkYmJkMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDRjYjdjMjNlNmE4MDQ0NGFmMDdlOTA2OGQzMzA5ZmNiNjY1NjU2ODgyZDRi
|
10
|
+
ODY0YmViMGY2NTkyZWU0YjlhZWVjZmI2MmI5ZDg2ZTkwMjYyNjEyMzg3NDcw
|
11
|
+
YmJmMmMyOWY5MmFhMDBmNTU5ZTNhNWEwODg2NjJhODMwN2E3ZTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjRhZGViZWVhNzllZGE5MDJlYmRlOTk5YzQzNGFjM2VkOWY2YmRkZjVhNDY4
|
14
|
+
NGIzOWY4MTIwNDA5ZjJiODRmOTZhMWUxMDc0MmRlZGViNWQ3NGVmMDA2NzI2
|
15
|
+
Y2UxZjY4ODU5OWE2MWQxOGQwNTRjZjIwNGI4MThjMjg3MjQxNzY=
|
data/lib/mistiq/defaults.rb
CHANGED
data/lib/mistiq/init.rb
CHANGED
@@ -1,154 +1,174 @@
|
|
1
1
|
module Mistiq
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
initializer "mistiq.configure_rails_initialization" do |app|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
4
|
+
#computes a hash of regex-ed routes, later used
|
5
|
+
#to redact links in the views
|
6
|
+
Rails.application.config.after_initialize do
|
7
|
+
@LINK_REGEX_HASH = Hash.new
|
8
|
+
|
9
|
+
#pre-load routes
|
10
|
+
Rails.application.reload_routes!
|
11
|
+
|
12
|
+
#get routes
|
13
|
+
routes = Rails.application.routes.routes
|
14
|
+
inspector = RoutesInspector.new(routes)
|
15
|
+
routes = inspector.get_routes
|
16
|
+
|
17
|
+
routes.each {
|
18
|
+
|r|
|
19
|
+
|
20
|
+
reqs = r[:reqs].split('#')
|
21
|
+
|
22
|
+
controller = reqs[0]
|
23
|
+
action = reqs[1]
|
24
|
+
|
25
|
+
if action != nil
|
26
|
+
temp = action.gsub(/[ ]{.*}/,"")
|
27
|
+
if temp != nil
|
28
|
+
action = temp
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
route = r[:path]
|
33
|
+
verb = r[:verb]
|
34
|
+
|
35
|
+
#get regex-ed route
|
36
|
+
regex_len = r[:regexp].length
|
37
|
+
regex = r[:regexp].slice(1..regex_len-2)
|
38
|
+
|
39
|
+
#if action#controller's data method is not GET and not POST
|
40
|
+
if verb != "GET" && verb != "POST" && verb != ""
|
41
|
+
method_regex = "data-method=(\"|')#{verb.downcase}(\"|')";
|
42
|
+
pattern = "<a.*#{method_regex}.*href=(\"|')#{regex}(\"|').*>.*<\/a>"
|
43
|
+
|
44
|
+
#also check if method_regex occurs after the href attribute
|
45
|
+
pattern = pattern+"@@@<a.*href=(\"|')#{regex}(\"|').*#{method_regex}.*>.*<\/a>"
|
46
|
+
elsif verb == "GET"
|
47
|
+
#if action#controller's data method is GET
|
48
|
+
#pattern = "<a(.*href=(\"|')#{pattern}(\"|'))(?!.*data\-method)[^<]*<\/a>"
|
49
|
+
pattern = "<a(?!.*data\-method)(.*href=(\"|')#{regex}(\"|')).*<\/a>"
|
50
|
+
else
|
51
|
+
#if action#controller's data method is POST
|
52
|
+
pattern = "POST"
|
53
|
+
end
|
54
|
+
|
55
|
+
if verb != ""
|
56
|
+
if @LINK_REGEX_HASH["#{controller}##{action}"] != nil
|
57
|
+
@LINK_REGEX_HASH["#{controller}##{action}"] = @LINK_REGEX_HASH["#{controller}##{action}"] + "@@@#{pattern}"
|
58
|
+
else
|
59
|
+
@LINK_REGEX_HASH["#{controller}##{action}"] = pattern
|
60
|
+
end
|
61
|
+
end
|
62
|
+
}
|
63
|
+
|
64
|
+
engine_routes = inspector.get_engine_routes
|
65
|
+
|
66
|
+
if engine_routes != nil
|
67
|
+
engine_routes.each {
|
68
|
+
|name, routes|
|
69
|
+
|
70
|
+
routes.each {
|
71
|
+
|r|
|
72
|
+
|
73
|
+
reqs = r[:reqs].split('#')
|
74
|
+
|
75
|
+
controller = reqs[0]
|
76
|
+
action = reqs[1]
|
77
|
+
|
78
|
+
if action != nil
|
79
|
+
temp = action.gsub(/[ ]{.*}/,"")
|
80
|
+
if temp != nil
|
81
|
+
action = temp
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
route = r[:path]
|
86
|
+
verb = r[:verb]
|
87
|
+
|
88
|
+
#get regex-ed route
|
89
|
+
regex_len = r[:regexp].length
|
90
|
+
regex = r[:regexp].slice(1..regex_len-2)
|
91
|
+
|
92
|
+
#if action#controller's data method is not GET and not POST
|
93
|
+
if verb != "GET" && verb != "POST" && verb != ""
|
94
|
+
method_regex = "data-method=(\"|')#{verb.downcase}(\"|')";
|
95
|
+
pattern = "<a.*#{method_regex}.*href=(\"|')#{regex}(\"|').*>.*<\/a>"
|
96
|
+
|
97
|
+
#also check if method_regex occurs after the href attribute
|
98
|
+
pattern = pattern+"@@@<a.*href=(\"|')#{regex}(\"|').*#{method_regex}.*>.*<\/a>"
|
99
|
+
elsif verb == "GET"
|
100
|
+
#if action#controller's data method is GET
|
101
|
+
#pattern = "<a(.*href=(\"|')#{pattern}(\"|'))(?!.*data\-method)[^<]*<\/a>"
|
102
|
+
pattern = "<a(?!.*data\-method)(.*href=(\"|')#{regex}(\"|')).*<\/a>"
|
103
|
+
else
|
104
|
+
#if action#controller's data method is POST
|
105
|
+
pattern = "POST"
|
106
|
+
end
|
107
|
+
|
108
|
+
if @LINK_REGEX_HASH["#{controller}##{action}"] != nil
|
109
|
+
@LINK_REGEX_HASH["#{controller}##{action}"] = @LINK_REGEX_HASH["#{controller}##{action}"] + "@@@#{pattern}"
|
110
|
+
else
|
111
|
+
@LINK_REGEX_HASH["#{controller}##{action}"] = pattern
|
112
|
+
end
|
113
|
+
}
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
puts "Link REGEX hash has been computed. #{@LINK_REGEX_HASH.size} routes were hashed."
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_regex_hash
|
122
|
+
@LINK_REGEX_HASH
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class RouteWrapper < SimpleDelegator
|
127
|
+
def endpoint
|
128
|
+
rack_app ? rack_app.inspect : "#{controller}##{action}"
|
129
|
+
end
|
100
130
|
|
101
|
-
|
102
|
-
|
103
|
-
end
|
131
|
+
def constraints
|
132
|
+
requirements.except(:controller, :action)
|
104
133
|
end
|
105
134
|
|
106
|
-
|
107
|
-
|
108
|
-
|
135
|
+
def rack_app(app = self.app)
|
136
|
+
@rack_app ||= begin
|
137
|
+
class_name = app.class.name.to_s
|
138
|
+
if class_name == "ActionDispatch::Routing::Mapper::Constraints"
|
139
|
+
rack_app(app.app)
|
140
|
+
elsif ActionDispatch::Routing::Redirect === app || class_name !~ /^ActionDispatch::Routing/
|
141
|
+
app
|
142
|
+
end
|
109
143
|
end
|
144
|
+
end
|
110
145
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
def rack_app(app = self.app)
|
116
|
-
@rack_app ||= begin
|
117
|
-
class_name = app.class.name.to_s
|
118
|
-
if class_name == "ActionDispatch::Routing::Mapper::Constraints"
|
119
|
-
rack_app(app.app)
|
120
|
-
elsif ActionDispatch::Routing::Redirect === app || class_name !~ /^ActionDispatch::Routing/
|
121
|
-
app
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def verb
|
127
|
-
super.source.gsub(/[$^]/, '')
|
128
|
-
end
|
146
|
+
def verb
|
147
|
+
super.source.gsub(/[$^]/, '')
|
148
|
+
end
|
129
149
|
|
130
|
-
|
131
|
-
|
132
|
-
|
150
|
+
def path
|
151
|
+
super.spec.to_s
|
152
|
+
end
|
133
153
|
|
134
|
-
|
135
|
-
|
136
|
-
|
154
|
+
def name
|
155
|
+
super.to_s
|
156
|
+
end
|
137
157
|
|
138
|
-
|
139
|
-
|
140
|
-
|
158
|
+
def regexp
|
159
|
+
__getobj__.path.to_regexp
|
160
|
+
end
|
141
161
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
162
|
+
def json_regexp
|
163
|
+
str = regexp.inspect.
|
164
|
+
sub('\\A' , '^').
|
165
|
+
sub('\\Z' , '$').
|
166
|
+
sub('\\z' , '$').
|
167
|
+
sub(/^\// , '').
|
168
|
+
sub(/\/[a-z]*$/ , '').
|
169
|
+
gsub(/\(\?#.+\)/ , '').
|
170
|
+
gsub(/\(\?-\w+:/ , '(').
|
171
|
+
gsub(/\s/ , '')
|
152
172
|
Regexp.new(str).source
|
153
173
|
end
|
154
174
|
|
@@ -175,9 +195,9 @@ module Mistiq
|
|
175
195
|
def engine?
|
176
196
|
rack_app && rack_app.respond_to?(:routes)
|
177
197
|
end
|
178
|
-
|
198
|
+
end
|
179
199
|
|
180
|
-
|
200
|
+
class RoutesInspector
|
181
201
|
def initialize(routes)
|
182
202
|
@engines = {}
|
183
203
|
@routes = routes
|
@@ -203,31 +223,31 @@ module Mistiq
|
|
203
223
|
end
|
204
224
|
end
|
205
225
|
|
206
|
-
|
226
|
+
def collect_routes(routes)
|
207
227
|
routes.collect do |route|
|
208
|
-
|
228
|
+
RouteWrapper.new(route)
|
209
229
|
end.reject do |route|
|
210
|
-
|
230
|
+
route.internal?
|
211
231
|
end.collect do |route|
|
212
|
-
|
232
|
+
collect_engine_routes(route)
|
213
233
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
234
|
+
{ name: route.name,
|
235
|
+
verb: route.verb,
|
236
|
+
path: route.path,
|
237
|
+
reqs: route.reqs,
|
238
|
+
regexp: route.json_regexp }
|
239
|
+
end
|
219
240
|
end
|
220
|
-
end
|
221
241
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
242
|
+
def collect_engine_routes(route)
|
243
|
+
name = route.endpoint
|
244
|
+
return unless route.engine?
|
245
|
+
return if @engines[name]
|
226
246
|
|
227
|
-
|
228
|
-
|
229
|
-
|
247
|
+
routes = route.rack_app.routes
|
248
|
+
if routes.is_a?(ActionDispatch::Routing::RouteSet)
|
249
|
+
@engines[name] = collect_routes(routes.routes)
|
250
|
+
end
|
230
251
|
end
|
231
|
-
|
232
|
-
|
233
|
-
end
|
252
|
+
end
|
253
|
+
end
|