mistiq 0.0.925 → 0.0.926

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTY1MDY2MDE2MWJkYmVmNzg3M2EyZDQ4NzhlNmZjMjcxOTk4MmRlMg==
4
+ OWE1YjgyZTBkYzRhYjA0ZDc1YWIzYzNlM2VlMzBmMTM1MmQ2ZTZiNQ==
5
5
  data.tar.gz: !binary |-
6
- MTQ3ZDQ4NjIwMTViNjg3MmFjOGRiN2RhMmRjZTI3ZWE5MjUwYzIzOA==
6
+ YzFkYTcxYTcwMGI0NjM2MTI1ZmUyZDIzYTJjYmQyZjYzMmZkYmJkMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDFkZWE1NDMwNGNmNGI0MmQ4ZWZjZWQ2ZmI5NmJlOGMzOTEyZmIyYmFiNjUx
10
- MGFiMjVkNDBmZjY3NTY0YWY3MDVmMWU4Mjk1Zjc5ODkyYTBiNTc0NWIxODUw
11
- MDZhMGUwYjI5YjE0ZTkxMmViY2JmMWQ4MGI3MDVlM2U3NWI1Zjg=
9
+ MDRjYjdjMjNlNmE4MDQ0NGFmMDdlOTA2OGQzMzA5ZmNiNjY1NjU2ODgyZDRi
10
+ ODY0YmViMGY2NTkyZWU0YjlhZWVjZmI2MmI5ZDg2ZTkwMjYyNjEyMzg3NDcw
11
+ YmJmMmMyOWY5MmFhMDBmNTU5ZTNhNWEwODg2NjJhODMwN2E3ZTU=
12
12
  data.tar.gz: !binary |-
13
- OTZlNmFkNDk3NzljZTU3YmYxMzI5YzYwZTM5MTM0YzVlZTEyNGZjYjE4Y2Q4
14
- NzgxMTgzZjQ2Nzg2OTg1ZWE0NjBmZjEyYmQxYzAxZTZlOGNkZmIzODBhYzUw
15
- YWJjZmVkODgwN2EyYmI5MjMyOThhZTcxYmRiYWJkM2JjODQ2NzE=
13
+ ZjRhZGViZWVhNzllZGE5MDJlYmRlOTk5YzQzNGFjM2VkOWY2YmRkZjVhNDY4
14
+ NGIzOWY4MTIwNDA5ZjJiODRmOTZhMWUxMDc0MmRlZGViNWQ3NGVmMDA2NzI2
15
+ Y2UxZjY4ODU5OWE2MWQxOGQwNTRjZjIwNGI4MThjMjg3MjQxNzY=
@@ -16,7 +16,7 @@ module Mistiq
16
16
  }
17
17
  end
18
18
 
19
- #disable all destroy operations across
19
+ #disable all create operations across
20
20
  #the rails application
21
21
  def disable_create_ops(strip_links=true)
22
22
  Railtie.get_regex_hash.each {
@@ -1,154 +1,174 @@
1
1
  module Mistiq
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "mistiq.configure_rails_initialization" do |app|
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
- route = r[:path]
26
- verb = r[:verb]
27
-
28
- #get regex-ed route
29
- regex_len = r[:regexp].length
30
- regex = r[:regexp].slice(1..regex_len-2)
31
-
32
- #if action#controller's data method is not GET and not POST
33
- if verb != "GET" && verb != "POST" && verb != ""
34
- method_regex = "data-method=(\"|')#{verb.downcase}(\"|')";
35
- pattern = "<a.*#{method_regex}.*href=(\"|')#{regex}(\"|').*>.*<\/a>"
36
-
37
- #also check if method_regex occurs after the href attribute
38
- pattern = pattern+"@@@<a.*href=(\"|')#{regex}(\"|').*#{method_regex}.*>.*<\/a>"
39
- elsif verb == "GET"
40
- #if action#controller's data method is GET
41
- #pattern = "<a(.*href=(\"|')#{pattern}(\"|'))(?!.*data\-method)[^<]*<\/a>"
42
- pattern = "<a(?!.*data\-method)(.*href=(\"|')#{regex}(\"|'))[^<]*<\/a>"
43
- else
44
- #if action#controller's data method is POST
45
- pattern = "POST"
46
- end
47
-
48
- if verb != ""
49
- @LINK_REGEX_HASH["#{controller}##{action}"] = pattern
50
- end
51
- }
52
-
53
- engine_routes = inspector.get_engine_routes
54
-
55
- if engine_routes != nil
56
- engine_routes.each {
57
- |name, routes|
58
-
59
- routes.each {
60
- |r|
61
-
62
- reqs = r[:reqs].split('#')
63
-
64
- controller = reqs[0]
65
- action = reqs[1]
66
-
67
- route = r[:path]
68
- verb = r[:verb]
69
-
70
- #get regex-ed route
71
- regex_len = r[:regexp].length
72
- regex = r[:regexp].slice(1..regex_len-2)
73
-
74
- #if action#controller's data method is not GET and not POST
75
- if verb != "GET" && verb != "POST" && verb != ""
76
- method_regex = "data-method=(\"|')#{verb.downcase}(\"|')";
77
- pattern = "<a.*#{method_regex}.*href=(\"|')#{regex}(\"|').*>.*<\/a>"
78
-
79
- #also check if method_regex occurs after the href attribute
80
- pattern = pattern+"@@@<a.*href=(\"|')#{regex}(\"|').*#{method_regex}.*>.*<\/a>"
81
- elsif verb == "GET"
82
- #if action#controller's data method is GET
83
- #pattern = "<a(.*href=(\"|')#{pattern}(\"|'))(?!.*data\-method)[^<]*<\/a>"
84
- pattern = "<a(?!.*data\-method)(.*href=(\"|')#{regex}(\"|'))[^<]*<\/a>"
85
- else
86
- #if action#controller's data method is POST
87
- pattern = "POST"
88
- end
89
-
90
- if verb != ""
91
- @LINK_REGEX_HASH["#{controller}##{action}"] = pattern
92
- end
93
- }
94
- }
95
- end
96
-
97
- puts "Link REGEX hash has been computed. #{@LINK_REGEX_HASH.size} routes were hashed."
98
- end
99
- end
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
- def get_regex_hash
102
- @LINK_REGEX_HASH
103
- end
131
+ def constraints
132
+ requirements.except(:controller, :action)
104
133
  end
105
134
 
106
- class RouteWrapper < SimpleDelegator
107
- def endpoint
108
- rack_app ? rack_app.inspect : "#{controller}##{action}"
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
- def constraints
112
- requirements.except(:controller, :action)
113
- end
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
- def path
131
- super.spec.to_s
132
- end
150
+ def path
151
+ super.spec.to_s
152
+ end
133
153
 
134
- def name
135
- super.to_s
136
- end
154
+ def name
155
+ super.to_s
156
+ end
137
157
 
138
- def regexp
139
- __getobj__.path.to_regexp
140
- end
158
+ def regexp
159
+ __getobj__.path.to_regexp
160
+ end
141
161
 
142
- def json_regexp
143
- str = regexp.inspect.
144
- sub('\\A' , '^').
145
- sub('\\Z' , '$').
146
- sub('\\z' , '$').
147
- sub(/^\// , '').
148
- sub(/\/[a-z]*$/ , '').
149
- gsub(/\(\?#.+\)/ , '').
150
- gsub(/\(\?-\w+:/ , '(').
151
- gsub(/\s/ , '')
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
- end
198
+ end
179
199
 
180
- class RoutesInspector
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
- def collect_routes(routes)
226
+ def collect_routes(routes)
207
227
  routes.collect do |route|
208
- RouteWrapper.new(route)
228
+ RouteWrapper.new(route)
209
229
  end.reject do |route|
210
- route.internal?
230
+ route.internal?
211
231
  end.collect do |route|
212
- collect_engine_routes(route)
232
+ collect_engine_routes(route)
213
233
 
214
- { name: route.name,
215
- verb: route.verb,
216
- path: route.path,
217
- reqs: route.reqs,
218
- regexp: route.json_regexp }
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
- def collect_engine_routes(route)
223
- name = route.endpoint
224
- return unless route.engine?
225
- return if @engines[name]
242
+ def collect_engine_routes(route)
243
+ name = route.endpoint
244
+ return unless route.engine?
245
+ return if @engines[name]
226
246
 
227
- routes = route.rack_app.routes
228
- if routes.is_a?(ActionDispatch::Routing::RouteSet)
229
- @engines[name] = collect_routes(routes.routes)
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
- end
232
- end
233
- end
252
+ end
253
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mistiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.925
4
+ version: 0.0.926
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Papancea