localtower 0.4.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -46
  3. data/app/controllers/localtower/pages_controller.rb +28 -42
  4. data/app/helpers/localtower/application_helper.rb +0 -18
  5. data/app/views/layouts/localtower/application.html.erb +20 -79
  6. data/app/views/localtower/pages/_alert_no_models.html.erb +3 -0
  7. data/app/views/localtower/pages/migrations.html.erb +50 -120
  8. data/app/views/localtower/pages/models.html.erb +53 -68
  9. data/app/views/localtower/pages/new_migration.html.erb +103 -0
  10. data/app/views/localtower/pages/new_model.html.erb +87 -0
  11. data/config/routes.rb +8 -17
  12. data/lib/localtower/generators/migration.rb +53 -181
  13. data/lib/localtower/generators/model.rb +53 -32
  14. data/lib/localtower/generators/service_objects/insert_array.rb +23 -0
  15. data/lib/localtower/generators/service_objects/insert_defaults.rb +15 -43
  16. data/lib/localtower/generators/service_objects/insert_indexes.rb +80 -0
  17. data/lib/localtower/generators/service_objects/insert_nullable.rb +23 -0
  18. data/lib/localtower/status.rb +12 -7
  19. data/lib/localtower/tools.rb +29 -24
  20. data/lib/localtower/version.rb +1 -1
  21. data/lib/localtower.rb +0 -1
  22. data/public/css/app.css +0 -49
  23. data/public/js/app.js +216 -86
  24. data/public/light-bootstrap-dashboard-master/assets/css/light-bootstrap-dashboard.css +9 -35
  25. data/public/screenshots/v1.0.0/migrations.png +0 -0
  26. data/public/screenshots/v1.0.0/models.png +0 -0
  27. data/public/screenshots/v1.0.0/new_migration.png +0 -0
  28. data/public/screenshots/v1.0.0/new_model.png +0 -0
  29. data/public/vendor/font-awesome.min.css +4 -0
  30. data/public/vendor/highlight-js-default.min.css +9 -0
  31. data/public/vendor/highlight.min.js +1198 -0
  32. data/public/{js → vendor}/masonry.pkgd.min.js +0 -0
  33. data/spec/dummy/Gemfile +0 -3
  34. data/spec/dummy/Gemfile.lock +78 -95
  35. data/spec/dummy/app/controllers/pages_controller.rb +0 -2
  36. data/spec/dummy/app/models/post.rb +3 -0
  37. data/spec/dummy/app/models/user.rb +3 -0
  38. data/spec/dummy/app/views/pages/home.html.erb +0 -1
  39. data/spec/dummy/config/database.yml +1 -1
  40. data/spec/dummy/config/environments/development.rb +3 -1
  41. data/spec/dummy/config/puma.rb +1 -1
  42. data/spec/dummy/db/migrate/20230119221452_create_users.rb +14 -0
  43. data/spec/dummy/db/migrate/20230119221751_change_users_at1674166670.rb +7 -0
  44. data/spec/dummy/db/migrate/20230119222054_create_posts.rb +11 -0
  45. data/spec/dummy/db/migrate/20230119222106_change_posts_at1674166865.rb +5 -0
  46. data/spec/dummy/db/schema.rb +41 -0
  47. data/spec/dummy/log/development.log +16030 -10038
  48. data/spec/dummy/log/localtower.log +1878 -439
  49. data/spec/dummy/log/test.log +0 -281
  50. data/spec/dummy/test/index.html +38 -0
  51. data/spec/dummy/tmp/pids/server.pid +1 -1
  52. data/spec/factories/migration.rb +25 -41
  53. data/spec/factories/model.rb +39 -25
  54. data/spec/lib/localtower/generators/migration_spec.rb +36 -63
  55. data/spec/lib/localtower/generators/model_spec.rb +43 -34
  56. data/spec/lib/localtower/generators/service_objects/insert_array_spec.rb +47 -0
  57. data/spec/lib/localtower/generators/service_objects/insert_defaults_spec.rb +30 -35
  58. data/spec/lib/localtower/generators/service_objects/insert_indexes_spec.rb +90 -0
  59. data/spec/lib/localtower/generators/service_objects/insert_nullable_spec.rb +61 -0
  60. data/spec/lib/localtower/tools_spec.rb +1 -11
  61. data/spec/spec_helper.rb +25 -5
  62. metadata +38 -30
  63. data/app/views/localtower/pages/dashboard.html.erb +0 -67
  64. data/app/views/localtower/pages/logs.html.erb +0 -84
  65. data/app/views/localtower/pages/relations.html.erb +0 -66
  66. data/app/views/localtower/pages/tasks.html.erb +0 -48
  67. data/lib/localtower/generators/relation.rb +0 -59
  68. data/lib/localtower/plugins/capture.rb +0 -197
  69. data/lib/tasks/localtower_tasks.rake +0 -4
  70. data/spec/dummy/lib/playground.rb +0 -0
  71. data/spec/dummy/log/localtower_capture_d8979d360722798f7b6eb1a2694a3791.json +0 -1
  72. data/spec/lib/localtower/generators/relation_spec.rb +0 -65
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localtower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Le Nouaille Diez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-30 00:00:00.000000000 Z
11
+ date: 2023-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.0.4
55
- - !ruby/object:Gem::Dependency
56
- name: rubyzip
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 1.2.1
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 1.2.1
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: pg
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -121,27 +107,25 @@ files:
121
107
  - app/controllers/localtower/pages_controller.rb
122
108
  - app/helpers/localtower/application_helper.rb
123
109
  - app/views/layouts/localtower/application.html.erb
124
- - app/views/localtower/pages/dashboard.html.erb
125
- - app/views/localtower/pages/logs.html.erb
110
+ - app/views/localtower/pages/_alert_no_models.html.erb
126
111
  - app/views/localtower/pages/migrations.html.erb
127
112
  - app/views/localtower/pages/models.html.erb
128
- - app/views/localtower/pages/relations.html.erb
129
- - app/views/localtower/pages/tasks.html.erb
113
+ - app/views/localtower/pages/new_migration.html.erb
114
+ - app/views/localtower/pages/new_model.html.erb
130
115
  - config/routes.rb
131
116
  - lib/localtower.rb
132
117
  - lib/localtower/engine.rb
133
118
  - lib/localtower/generators/migration.rb
134
119
  - lib/localtower/generators/model.rb
135
- - lib/localtower/generators/relation.rb
120
+ - lib/localtower/generators/service_objects/insert_array.rb
136
121
  - lib/localtower/generators/service_objects/insert_defaults.rb
137
- - lib/localtower/plugins/capture.rb
122
+ - lib/localtower/generators/service_objects/insert_indexes.rb
123
+ - lib/localtower/generators/service_objects/insert_nullable.rb
138
124
  - lib/localtower/status.rb
139
125
  - lib/localtower/tools.rb
140
126
  - lib/localtower/version.rb
141
- - lib/tasks/localtower_tasks.rake
142
127
  - public/css/app.css
143
128
  - public/js/app.js
144
- - public/js/masonry.pkgd.min.js
145
129
  - public/light-bootstrap-dashboard-master/assets/css/animate.min.css
146
130
  - public/light-bootstrap-dashboard-master/assets/css/bootstrap.min.css
147
131
  - public/light-bootstrap-dashboard-master/assets/css/demo.css
@@ -192,6 +176,14 @@ files:
192
176
  - public/screenshots/v0.1.6/3_relations.png
193
177
  - public/screenshots/v0.1.6/4_migrations.png
194
178
  - public/screenshots/v0.1.6/5_capture.png
179
+ - public/screenshots/v1.0.0/migrations.png
180
+ - public/screenshots/v1.0.0/models.png
181
+ - public/screenshots/v1.0.0/new_migration.png
182
+ - public/screenshots/v1.0.0/new_model.png
183
+ - public/vendor/font-awesome.min.css
184
+ - public/vendor/highlight-js-default.min.css
185
+ - public/vendor/highlight.min.js
186
+ - public/vendor/masonry.pkgd.min.js
195
187
  - spec/dummy/Gemfile
196
188
  - spec/dummy/Gemfile.lock
197
189
  - spec/dummy/README.md
@@ -208,6 +200,8 @@ files:
208
200
  - spec/dummy/app/jobs/application_job.rb
209
201
  - spec/dummy/app/mailers/application_mailer.rb
210
202
  - spec/dummy/app/models/application_record.rb
203
+ - spec/dummy/app/models/post.rb
204
+ - spec/dummy/app/models/user.rb
211
205
  - spec/dummy/app/views/layouts/application.html.erb
212
206
  - spec/dummy/app/views/layouts/mailer.html.erb
213
207
  - spec/dummy/app/views/layouts/mailer.text.erb
@@ -242,11 +236,15 @@ files:
242
236
  - spec/dummy/config/routes.rb
243
237
  - spec/dummy/config/secrets.yml
244
238
  - spec/dummy/config/spring.rb
245
- - spec/dummy/lib/playground.rb
239
+ - spec/dummy/db/migrate/20230119221452_create_users.rb
240
+ - spec/dummy/db/migrate/20230119221751_change_users_at1674166670.rb
241
+ - spec/dummy/db/migrate/20230119222054_create_posts.rb
242
+ - spec/dummy/db/migrate/20230119222106_change_posts_at1674166865.rb
243
+ - spec/dummy/db/schema.rb
246
244
  - spec/dummy/log/development.log
247
245
  - spec/dummy/log/localtower.log
248
- - spec/dummy/log/localtower_capture_d8979d360722798f7b6eb1a2694a3791.json
249
246
  - spec/dummy/log/test.log
247
+ - spec/dummy/test/index.html
250
248
  - spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-Y/-YOiiBKqc2UODHFjctm8xc7xFoZaL7zOjWQj6qQ2wyE.cache
251
249
  - spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-d/-dwueM4vmPt8L51S3jeSyg_AjGDcj0GUN6pDpCA1gCg.cache
252
250
  - spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0g/0gaJnJQdtd2ACbihXxn8OnjLWlDjnQ_WxfgOpbiLzhg.cache
@@ -320,8 +318,10 @@ files:
320
318
  - spec/factories/model.rb
321
319
  - spec/lib/localtower/generators/migration_spec.rb
322
320
  - spec/lib/localtower/generators/model_spec.rb
323
- - spec/lib/localtower/generators/relation_spec.rb
321
+ - spec/lib/localtower/generators/service_objects/insert_array_spec.rb
324
322
  - spec/lib/localtower/generators/service_objects/insert_defaults_spec.rb
323
+ - spec/lib/localtower/generators/service_objects/insert_indexes_spec.rb
324
+ - spec/lib/localtower/generators/service_objects/insert_nullable_spec.rb
325
325
  - spec/lib/localtower/tools_spec.rb
326
326
  - spec/spec_helper.rb
327
327
  homepage: https://github.com/damln/localtower
@@ -350,6 +350,8 @@ test_files:
350
350
  - spec/spec_helper.rb
351
351
  - spec/dummy/app/mailers/application_mailer.rb
352
352
  - spec/dummy/app/models/application_record.rb
353
+ - spec/dummy/app/models/post.rb
354
+ - spec/dummy/app/models/user.rb
353
355
  - spec/dummy/app/jobs/application_job.rb
354
356
  - spec/dummy/app/controllers/application_controller.rb
355
357
  - spec/dummy/app/controllers/pages_controller.rb
@@ -364,6 +366,7 @@ test_files:
364
366
  - spec/dummy/app/helpers/application_helper.rb
365
367
  - spec/dummy/app/channels/application_cable/connection.rb
366
368
  - spec/dummy/app/channels/application_cable/channel.rb
369
+ - spec/dummy/test/index.html
367
370
  - spec/dummy/bin/update
368
371
  - spec/dummy/bin/rake
369
372
  - spec/dummy/bin/setup
@@ -396,10 +399,13 @@ test_files:
396
399
  - spec/dummy/config.ru
397
400
  - spec/dummy/README.md
398
401
  - spec/dummy/Rakefile
399
- - spec/dummy/lib/playground.rb
402
+ - spec/dummy/db/schema.rb
403
+ - spec/dummy/db/migrate/20230119221751_change_users_at1674166670.rb
404
+ - spec/dummy/db/migrate/20230119221452_create_users.rb
405
+ - spec/dummy/db/migrate/20230119222054_create_posts.rb
406
+ - spec/dummy/db/migrate/20230119222106_change_posts_at1674166865.rb
400
407
  - spec/dummy/Gemfile
401
408
  - spec/dummy/log/localtower.log
402
- - spec/dummy/log/localtower_capture_d8979d360722798f7b6eb1a2694a3791.json
403
409
  - spec/dummy/log/test.log
404
410
  - spec/dummy/log/development.log
405
411
  - spec/dummy/Gemfile.lock
@@ -477,5 +483,7 @@ test_files:
477
483
  - spec/lib/localtower/tools_spec.rb
478
484
  - spec/lib/localtower/generators/migration_spec.rb
479
485
  - spec/lib/localtower/generators/service_objects/insert_defaults_spec.rb
486
+ - spec/lib/localtower/generators/service_objects/insert_array_spec.rb
487
+ - spec/lib/localtower/generators/service_objects/insert_nullable_spec.rb
488
+ - spec/lib/localtower/generators/service_objects/insert_indexes_spec.rb
480
489
  - spec/lib/localtower/generators/model_spec.rb
481
- - spec/lib/localtower/generators/relation_spec.rb
@@ -1,67 +0,0 @@
1
- <% content_for :title do %>Schema<% end %>
2
-
3
- <div class="row">
4
- <div class="col-md-12">
5
- <div class="content">
6
- <div class="">
7
-
8
- <div class="grid">
9
- <div class="grid-sizer"></div>
10
-
11
- <% ::Localtower::Tools.models_presented.each do |model| %>
12
-
13
- <div class="grid-item text-small card">
14
- <div class="text-center">
15
- <h5><%= model[:name] %></h5>
16
- </div>
17
-
18
- <table class="table table-hover table-striped table-condensed">
19
- <thead>
20
- <th>Field</th>
21
- <th>Type</th>
22
- <th>Belongs To</th>
23
- <th>Index?</th>
24
- </thead>
25
-
26
- <tbody>
27
- <% model[:attributes_list].each do |attribute_data| %>
28
-
29
- <tr>
30
- <td>
31
- <code>
32
- <%= attribute_data["name"] %>
33
- </code>
34
- </td>
35
-
36
- <td>
37
- <%= attribute_data["type_clean"] %>
38
- </td>
39
-
40
- <td>
41
- <% if attribute_data["belongs_to"] %>
42
- <span class="label label-primary">
43
- <%= attribute_data["belongs_to"] %>
44
- </span>
45
- <% end %>
46
- </td>
47
-
48
- <td>
49
- <% if attribute_data["index"].any? %>
50
- <span class="label label-success">Yes</span>
51
- <% else %>
52
- <span class="label label-default">No</span>
53
- <% end %>
54
- </td>
55
- </tr>
56
- <% end %>
57
- </tbody>
58
- </table>
59
- </div>
60
- <% end %>
61
- <div class="clearfix"></div>
62
- </div>
63
-
64
- </div>
65
- </div>
66
- </div>
67
- </div>
@@ -1,84 +0,0 @@
1
- <style type="text/css">
2
- .string { color: green; }
3
- .number { color: darkorange; }
4
- .boolean { color: blue; }
5
- .null { color: magenta; }
6
- .key { color: red; }
7
-
8
- .code {
9
- font: 12px Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;
10
- }
11
-
12
- .value {
13
- padding: 10px;
14
- border: 1px solid #cacaca;
15
- line-height: 1.2em;
16
- overflow:auto;
17
- max-height: 800px;
18
- max-width: 800px;
19
- -moz-background-clip: padding;
20
- -webkit-background-clip: padding-box;
21
- background-clip: padding-box;
22
- background-color: #FAFAFB;
23
- color: #393939;
24
- margin: 0px;
25
- display: block;
26
- }
27
- </style>
28
- <% content_for :title do %>Logs<% end %>
29
- <div class="row">
30
- <div class="col-md-12">
31
- <div class="card">
32
- <div class="header">
33
- <h4 class="title">
34
- <pre>Localtower::Plugins::Capture.new(self, binding).save</pre>
35
- </h4>
36
- </div>
37
- <div class="content">
38
- <table class="table">
39
- <thead>
40
- <th>TYPE</th>
41
- <th>IN CLASS</th>
42
- <th>IN METHOD</th>
43
- <th>VARIABLE</th>
44
- <th>VALUE</th>
45
- </thead>
46
- <tbody>
47
- <% @logs.each do |log| %>
48
- <% log["variables"].each do |item| %>
49
- <tr>
50
- <td>
51
- <span class="label label-success">
52
- <%= item["type"] %>
53
- </span>
54
- </td>
55
- <td>
56
- <span>
57
- <a class="code" href="<%= file_link(item["meta"]["sublime_path"]) %>">
58
- <%= item["meta"]["from_klass"] %>
59
- </a>
60
- </span>
61
- </td>
62
- <td>
63
- <span class="code">
64
- def <%= item["meta"]["from_method"] %>()
65
- </span>
66
- </td>
67
- <td>
68
- <span class="code">
69
- <%= item["event_name"] %>
70
- </span>
71
- </td>
72
- <td>
73
- <a href="<%= log_var_path(log["md5"], item["event_name"]) %>">open</a>
74
- <pre class="value json code"><%= Localtower::Plugins::Capture.printable(item["returned"]) %></pre>
75
- </td>
76
- </tr>
77
- <% end %>
78
- <% end %>
79
- </tbody>
80
- </table>
81
- </div>
82
- </div>
83
- </div>
84
- </div>
@@ -1,66 +0,0 @@
1
- <% content_for :title do %>Relations<% end %>
2
-
3
- <div class="row">
4
- <div class="col-md-12">
5
- <div class="card">
6
- <div class="header">
7
- <h4 class="title"></h4>
8
-
9
- <% if not ::Localtower::Tools.enought_models_for_relation? %>
10
- <div class="alert alert-danger text-center" role="alert">
11
- <a href="#" class="alert-link">You need at least 2 models to create a relation.</a>
12
- </div>
13
- <% end %>
14
- </div>
15
-
16
- <div class="content">
17
-
18
- <%= form_tag relations_path, class: "form" do %>
19
- <div class="row">
20
- <div class="form-group">
21
- <div class="col-md-offset-4 col-sm-offset-3 col-md-4 col-sm-6">
22
- <div class="form-group">
23
- <div class="text-center">
24
- <label>Name of the relation (optional, will use Rails conventions by default)</label>
25
- </div>
26
- <input type="text" name="relations[model_name]" class="form-control">
27
- </div>
28
- </div>
29
-
30
- <div class="clearfix"></div>
31
-
32
- <div class="col-md-5 col-sm-5">
33
- <label>Model 1:</label>
34
-
35
- <%= select("relations", "model_one_name", ::Localtower::Tools.models.collect {|p| [ p, p ] }, {include_blank: false}, class: "form-control") %>
36
- </div>
37
-
38
- <div class="col-md-2 col-sm-2">
39
- <div class="text-center">
40
- <br>
41
- <i class="pe-7s-loop" style="font-size: 3em;"></i>
42
- </div>
43
- </div>
44
-
45
- <div class="col-md-5 col-sm-5">
46
- <label>Model 2:</label>
47
- <%= select("relations", "model_two_name", ::Localtower::Tools.models.collect {|p| [ p, p ] }, {include_blank: false}, class: "form-control") %>
48
- </div>
49
- </div>
50
- </div>
51
-
52
- <hr>
53
-
54
- <div class="row">
55
- <div class="col-md-12 text-center">
56
- <button name="relations[run_migrate]" type="submit" value="true" class="btn btn-success" data-selector="submit">
57
- Create the relation and <b>migrate</b>
58
- </button>
59
- </div>
60
- </div>
61
-
62
- <% end %>
63
- </div>
64
- </div>
65
- </div>
66
- </div>
@@ -1,48 +0,0 @@
1
- <% content_for :title do %>Tasks<% end %>
2
-
3
- <div class="row">
4
- <div class="col-md-12">
5
- <div class="card">
6
- <div class="header">
7
- <h4 class="title"></h4>
8
- </div>
9
- <div class="content">
10
-
11
- <%= form_tag tasks_path, class: "form" do %>
12
- <div class="row">
13
- <div class="form-group">
14
- <div class="col-md-12">
15
- <div class="form-group">
16
- <table class="table table-hover table-striped">
17
- <thead>
18
- <th>Task</th>
19
- <th></th>
20
- </thead>
21
-
22
- <tbody data-selector="tbody">
23
- <% @tasks.each do |task_str| %>
24
- <tr data-selector="tr">
25
- <td>
26
- <code>
27
- <%=task_str%>
28
- </code>
29
- <input type="hidden" name="task[name]" value="<%= task_str %>" class="form-control">
30
- </td>
31
- <td>
32
- <button name="" type="submit" class="btn btn-success" data-selector="submit">
33
- RUN
34
- </button>
35
- </td>
36
- </tr>
37
- <% end %>
38
- </tbody>
39
- </table>
40
- </div>
41
- </div>
42
- </div>
43
- </div>
44
- <% end %>
45
- </div>
46
- </div>
47
- </div>
48
- </div>
@@ -1,59 +0,0 @@
1
- module Localtower
2
- module Generators
3
- class Relation
4
- def initialize(opts)
5
- @opts = JSON[opts.to_json]
6
- end
7
-
8
- def run
9
- model_one_name = @opts["model_one_name"]
10
- model_two_name = @opts["model_two_name"]
11
-
12
- if not model_one_name.present? and not model_two_name.present?
13
- return nil
14
- end
15
-
16
- if @opts["model_name"].present?
17
- model_name = @opts["model_name"].capitalize
18
- else
19
- model_name = "#{model_one_name.capitalize}#{model_two_name.capitalize}"
20
- end
21
-
22
- data = {
23
- run_migrate: true,
24
- model_name: model_name,
25
- attributes: [
26
- {
27
- attribute_name: model_one_name.downcase,
28
- attribute_type: "references"
29
- },
30
- {
31
- attribute_name: model_two_name.downcase,
32
- attribute_type: "references"
33
- },
34
- ]
35
- }
36
-
37
- ::Localtower::Generators::Model.new(data.deep_stringify_keys).run
38
-
39
- # model 1:
40
- file = "#{Rails.root}/app/models/#{model_one_name.underscore}.rb"
41
- after = /class #{model_one_name} < ApplicationRecord\n/
42
- line1 = " has_many :#{model_name.pluralize.underscore}\n"
43
- line2 = " has_many :#{model_two_name.pluralize.underscore}, through: :#{model_name.pluralize.underscore}\n"
44
-
45
- ::Localtower::Tools::ThorTools.new.insert_after_word(file, after, line1)
46
- ::Localtower::Tools::ThorTools.new.insert_after_word(file, after, line2)
47
-
48
- # model 2:
49
- file = "#{Rails.root}/app/models/#{model_two_name.underscore}.rb"
50
- after = /class #{model_two_name} < ApplicationRecord\n/
51
- line1 = " has_many :#{model_name.pluralize.underscore}\n"
52
- line2 = " has_many :#{model_one_name.pluralize.underscore}, through: :#{model_name.pluralize.underscore}\n"
53
-
54
- ::Localtower::Tools::ThorTools.new.insert_after_word(file, after, line1)
55
- ::Localtower::Tools::ThorTools.new.insert_after_word(file, after, line2)
56
- end
57
- end
58
- end
59
- end
@@ -1,197 +0,0 @@
1
- module Localtower
2
- module Plugins
3
- class Capture
4
- LOG_FILE = lambda { "#{Rails.root}/log/localtower_capture.log" }
5
- LOG_PATH = lambda { "#{Rails.root}/log" }
6
- EXCLUDE_INSTANCE_VARIABLES = [
7
- "@_action_has_layout",
8
- "@_routes",
9
- "@_headers",
10
- "@_status",
11
- "@_request",
12
- "@__react_component_helper",
13
- "@_response",
14
- "@_env",
15
- "@env",
16
- "@controller",
17
- "@_lookup_context",
18
- "@_action_name",
19
- "@_response_body",
20
- ]
21
-
22
- class << self
23
- def printable(content)
24
- if content.respond_to?(:to_json)
25
- JSON.pretty_generate(content)
26
- else
27
- content.to_s
28
- end
29
- end
30
-
31
- def log_from_md5(md5)
32
- file = Dir["#{Localtower::Plugins::Capture::LOG_PATH.call}/localtower*#{md5}*"][0]
33
- JSON.parse(open(file).read)
34
- end
35
-
36
- def type_of(value)
37
- if value.instance_of?(Float); return Float.to_s; end;
38
- if value.instance_of?(Integer); return Integer.to_s; end;
39
- if value.instance_of?(String); return String.to_s; end;
40
- if value.instance_of?(Array); return Array.to_s; end;
41
- if value.instance_of?(Hash); return Hash.to_s; end;
42
- if value.instance_of?(ApplicationController); return ApplicationController.to_s; end;
43
- if value.instance_of?(NilClass); return NilClass.to_s; end;
44
-
45
- nil
46
- end
47
- end
48
-
49
- def initialize(context = nil, context_binding = nil)
50
- @context = context # self
51
- @context_binding = context_binding # binding
52
- end
53
-
54
- def logs
55
- list = []
56
-
57
- Dir["#{LOG_PATH.call}/localtower_capture_*.json"].each do |file|
58
- json = JSON.parse(open(file).read)
59
- list << json
60
- end
61
-
62
- list
63
- end
64
-
65
- def my_logger
66
- @@my_logger ||= Logger.new(LOG_FILE.call)
67
- @@my_logger.formatter = proc do |severity, datetime, progname, msg|
68
- "#{msg}\n"
69
- end
70
-
71
- @@my_logger
72
- end
73
-
74
- def values
75
- hash = {}
76
-
77
- callers = @context.send(:caller)
78
- a = callers[1] # xx/xx/app/controllers/clients/events_controller.rb:57:in `new'
79
- a = a.split(Rails.root.to_s).last # events_controller.rb:57:in `new'
80
- a = a.split("\:")
81
-
82
-
83
- file = a[0].strip
84
- line_number = a[1].strip
85
- method = a[2].strip.gsub("in \`", "").gsub("\'", "")
86
-
87
- sublime_path = "#{callers[1].split(":")[0]}:#{line_number}"
88
-
89
- hash["class"] = self.klass_name
90
- hash["file_name"] = file
91
- hash["file"] = "#{file}##{method}:#{line_number}"
92
- hash["line_number"] = line_number
93
- hash["method"] = method
94
- hash["md5"] = Digest::MD5.hexdigest(hash["file"])
95
- hash["type"] = "CAPTURE_METHOD"
96
- hash["time"] = Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%L')
97
-
98
- variables = []
99
-
100
- @context_binding.local_variables.each do |var|
101
- next if EXCLUDE_INSTANCE_VARIABLES.include?(var.to_s)
102
-
103
- value = @context_binding.local_variable_get(var)
104
- klass = self.class.type_of(value)
105
-
106
- data = {
107
- type: 'CAPTURE',
108
- time: Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%L'),
109
- event_name: var,
110
- identifier: nil,
111
- returned: value,
112
- meta: {
113
- from_klass: hash["class"],
114
- from_method: hash["method"],
115
- klass: klass.to_s,
116
- method: method.to_s,
117
- callers: callers,
118
- sublime_path: sublime_path,
119
- file: hash["file"],
120
- line: line_number
121
- }
122
- }
123
-
124
- variables << data
125
- end
126
-
127
- @context.instance_variables.each do |var|
128
- next if EXCLUDE_INSTANCE_VARIABLES.include?(var.to_s)
129
-
130
- value = @context.instance_variable_get(var.to_sym)
131
- klass = self.class.type_of(value)
132
-
133
- data = {
134
- type: 'CAPTURE',
135
- time: Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%L'),
136
- event_name: var,
137
- identifier: nil,
138
- returned: value,
139
- meta: {
140
- from_klass: hash["class"],
141
- from_method: hash["method"],
142
- klass: klass.to_s,
143
- method: method.to_s,
144
- # arguments: data[:arguments],
145
- callers: callers,
146
- # table_name: data[:table_name],
147
- # sql: data[:sql],
148
- sublime_path: sublime_path,
149
- file: hash["file"],
150
- line: line_number
151
- }
152
- }
153
-
154
- variables << data
155
- end
156
-
157
- hash["variables"] = variables
158
-
159
- hash
160
- end
161
-
162
- def klass_name
163
- value = if @context.class == "Class"
164
- @context
165
- else
166
- @context.class
167
- end
168
-
169
- value.to_s
170
- end
171
-
172
- def clear
173
- Dir["#{LOG_PATH.call}/localtower_capture_*.json"].each do |file|
174
- File.delete(file)
175
- end
176
-
177
- self
178
- end
179
-
180
- def save
181
- # We don't want to save logs in production:
182
- return nil if Rails.env.production?
183
-
184
- self.clear
185
-
186
- data = self.values
187
- file = "#{LOG_PATH.call}/localtower_capture_#{data['md5']}.json"
188
-
189
- File.open(file, 'w') { |f| f.write(data.to_json) }
190
- end
191
-
192
- def log(str)
193
- my_logger.info(str)
194
- end
195
- end
196
- end
197
- end