rails_spotlight 0.4.2 → 0.5.0
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 +4 -4
- data/.rubocop.yml +4 -4
- data/Dockerfile +1 -2
- data/Dockerfile-rails-6.0 +2 -2
- data/Dockerfile-rails-6.1 +2 -2
- data/Dockerfile-rails-7.1 +44 -0
- data/{Dockerfile-rails-7.0 → Dockerfile-rails-8.0} +3 -3
- data/{Dockerfile-rails-5.2 → Dockerfile-rails-8.0.2} +10 -5
- data/README.md +47 -15
- data/docker-compose.yml +14 -9
- data/docs/assets/images/sql_execution_toggle.gif +0 -0
- data/fake_spec_res/config/rails_spotlight.yml +47 -0
- data/fake_spec_res/rails_spotlight_spec.rb +23 -5
- data/lib/rails_spotlight/app_notifications.rb +2 -3
- data/lib/rails_spotlight/channels/handlers/{live_console_handler.rb → console_handler.rb} +3 -3
- data/lib/rails_spotlight/channels/handlers/logs_handler.rb +1 -1
- data/lib/rails_spotlight/channels/handlers.rb +3 -3
- data/lib/rails_spotlight/channels/spotlight_channel.rb +20 -1
- data/lib/rails_spotlight/configuration.rb +40 -58
- data/lib/rails_spotlight/event.rb +21 -5
- data/lib/rails_spotlight/log_interceptor.rb +34 -57
- data/lib/rails_spotlight/middlewares/handlers/base_action_handler.rb +45 -55
- data/lib/rails_spotlight/middlewares/handlers/code_analysis_action_handler.rb +8 -13
- data/lib/rails_spotlight/middlewares/handlers/console_action_handler.rb +8 -12
- data/lib/rails_spotlight/middlewares/handlers/directory_index_action_handler.rb +16 -27
- data/lib/rails_spotlight/middlewares/handlers/file_action_handler.rb +21 -55
- data/lib/rails_spotlight/middlewares/handlers/meta_action_handler.rb +3 -8
- data/lib/rails_spotlight/middlewares/handlers/not_found_action_handler.rb +1 -1
- data/lib/rails_spotlight/middlewares/handlers/sql_action_handler.rb +18 -35
- data/lib/rails_spotlight/middlewares/handlers/verify_action_handler.rb +1 -3
- data/lib/rails_spotlight/middlewares/header_marker.rb +1 -3
- data/lib/rails_spotlight/middlewares/request_completed.rb +2 -2
- data/lib/rails_spotlight/rails_command_executor.rb +3 -5
- data/lib/rails_spotlight/railtie.rb +2 -4
- data/lib/rails_spotlight/render_view_reporter.rb +3 -3
- data/lib/rails_spotlight/storage.rb +4 -14
- data/lib/rails_spotlight/utils.rb +1 -1
- data/lib/rails_spotlight/version.rb +1 -1
- data/lib/tasks/init.rake +26 -6
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97fa9dc74cea28532602f60c83e5dd0c5ca79f6bd63ad68f8d1b1cd84a5ce0b7
|
4
|
+
data.tar.gz: 002f2d9081c6877a6c569f49db2f17e2fcb02d4cc2800e0a69cff5375c89ab2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 637f0d742d42129342fc6733a823e72c2fdf9f00c627dd137f78f2f7b0801108c5c522c208123383139f84335e6d02c3e3493efd986b0bd328e8097f7d769678
|
7
|
+
data.tar.gz: 80eac812bd515eda62d6ed28123b114b287e35b8467542837ef789fda7f43498f2188227ec5c3eb8959691d4b6d0b70d7279fe9b2b166fec2b48d18c92df8921
|
data/.rubocop.yml
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion:
|
2
|
+
TargetRubyVersion: 3.1
|
3
3
|
DefaultFormatter: progress
|
4
|
-
SuggestExtensions:
|
5
|
-
rubocop-rake: true
|
6
|
-
rubocop-rspec: true
|
4
|
+
SuggestExtensions: false
|
7
5
|
NewCops: enable
|
8
6
|
Exclude:
|
9
7
|
- "bin/**/*"
|
@@ -11,6 +9,8 @@ AllCops:
|
|
11
9
|
- "tmp/**/*"
|
12
10
|
- "extensions/**/*"
|
13
11
|
- "spec/**/*"
|
12
|
+
- "fake_spec_res/**/*"
|
13
|
+
- "lib/tasks/init.rake"
|
14
14
|
|
15
15
|
Style/StringLiterals:
|
16
16
|
Enabled: true
|
data/Dockerfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
FROM ruby:2
|
1
|
+
FROM ruby:3.1.2-alpine
|
2
2
|
|
3
3
|
RUN apk add --update --no-cache \
|
4
4
|
build-base git openssh
|
@@ -10,7 +10,6 @@ COPY Gemfile /app
|
|
10
10
|
COPY rails_spotlight.gemspec /app
|
11
11
|
COPY lib/rails_spotlight/version.rb /app/lib/rails_spotlight/version.rb
|
12
12
|
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
|
13
|
-
RUN gem update --system 3.2.3
|
14
13
|
RUN gem install bundler -v 2.4.6
|
15
14
|
RUN bundle install
|
16
15
|
|
data/Dockerfile-rails-6.0
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
FROM ruby:2
|
1
|
+
FROM ruby:3.1.2-alpine
|
2
2
|
|
3
3
|
RUN apk add --update --no-cache \
|
4
4
|
build-base \
|
@@ -18,7 +18,6 @@ WORKDIR /app
|
|
18
18
|
|
19
19
|
RUN bundle config set force_ruby_platform true
|
20
20
|
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
|
21
|
-
RUN gem update --system 3.2.3
|
22
21
|
RUN gem install bundler -v 2.4.6
|
23
22
|
RUN gem install rails -v 6.0.6
|
24
23
|
RUN gem install rspec-rails -v 4.1.1
|
@@ -31,6 +30,7 @@ RUN bundle install
|
|
31
30
|
RUN rails generate rspec:install
|
32
31
|
|
33
32
|
COPY fake_spec_res/routes.rb /app/config/
|
33
|
+
COPY fake_spec_res/config/rails_spotlight.yml /app/config/
|
34
34
|
COPY fake_spec_res/dummy_controller.rb /app/app/controllers/
|
35
35
|
COPY fake_spec_res/dummy /app/app/views/dummy
|
36
36
|
COPY fake_spec_res/rails_spotlight_spec.rb /app/spec/integration/
|
data/Dockerfile-rails-6.1
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
FROM ruby:2
|
1
|
+
FROM ruby:3.1.2-alpine
|
2
2
|
|
3
3
|
RUN apk add --update --no-cache \
|
4
4
|
build-base \
|
@@ -18,7 +18,6 @@ WORKDIR /app
|
|
18
18
|
|
19
19
|
RUN bundle config set force_ruby_platform true
|
20
20
|
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
|
21
|
-
RUN gem update --system 3.2.3
|
22
21
|
RUN gem install bundler -v 2.4.6
|
23
22
|
RUN gem install rails -v 6.1.7
|
24
23
|
RUN gem install rspec-rails -v 4.1.1
|
@@ -31,6 +30,7 @@ RUN bundle install
|
|
31
30
|
RUN rails generate rspec:install
|
32
31
|
|
33
32
|
COPY fake_spec_res/routes.rb /app/config/
|
33
|
+
COPY fake_spec_res/config/rails_spotlight.yml /app/config/
|
34
34
|
COPY fake_spec_res/dummy_controller.rb /app/app/controllers/
|
35
35
|
COPY fake_spec_res/dummy /app/app/views/dummy
|
36
36
|
COPY fake_spec_res/rails_spotlight_spec.rb /app/spec/integration/
|
@@ -0,0 +1,44 @@
|
|
1
|
+
FROM ruby:3.1.2-alpine
|
2
|
+
|
3
|
+
RUN apk add --update --no-cache \
|
4
|
+
build-base \
|
5
|
+
curl-dev \
|
6
|
+
git \
|
7
|
+
nodejs \
|
8
|
+
shared-mime-info \
|
9
|
+
sqlite-dev \
|
10
|
+
tzdata \
|
11
|
+
yaml-dev \
|
12
|
+
yarn \
|
13
|
+
zlib-dev \
|
14
|
+
gcompat \
|
15
|
+
ruby-dev
|
16
|
+
|
17
|
+
RUN mkdir /app /gem
|
18
|
+
WORKDIR /app
|
19
|
+
|
20
|
+
RUN bundle config set force_ruby_platform true
|
21
|
+
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
|
22
|
+
# RUN gem update --system 3.2.3
|
23
|
+
RUN gem install bundler -v 2.4.6
|
24
|
+
RUN gem install rails -v 7.1
|
25
|
+
RUN gem install rspec-rails
|
26
|
+
RUN rails new .
|
27
|
+
|
28
|
+
COPY . /gem
|
29
|
+
RUN bundle add rails_spotlight --path /gem
|
30
|
+
RUN echo 'gem "rspec-rails"' >> "Gemfile"
|
31
|
+
RUN bundle install
|
32
|
+
RUN rails generate rspec:install
|
33
|
+
|
34
|
+
COPY fake_spec_res/routes.rb /app/config/
|
35
|
+
COPY fake_spec_res/config/rails_spotlight.yml /app/config/
|
36
|
+
COPY fake_spec_res/dummy_controller.rb /app/app/controllers/
|
37
|
+
COPY fake_spec_res/dummy /app/app/views/dummy
|
38
|
+
COPY fake_spec_res/rails_spotlight_spec.rb /app/spec/integration/
|
39
|
+
|
40
|
+
RUN bundle exec rails db:migrate
|
41
|
+
|
42
|
+
ENV PARALLEL_WORKERS 1
|
43
|
+
|
44
|
+
CMD ["bin/rake"]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
FROM ruby:3.
|
1
|
+
FROM ruby:3.2.2-alpine
|
2
2
|
|
3
3
|
RUN apk add --update --no-cache \
|
4
4
|
build-base \
|
@@ -18,9 +18,8 @@ WORKDIR /app
|
|
18
18
|
|
19
19
|
RUN bundle config set force_ruby_platform true
|
20
20
|
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
|
21
|
-
RUN gem update --system 3.2.3
|
22
21
|
RUN gem install bundler -v 2.4.6
|
23
|
-
RUN gem install rails -v
|
22
|
+
RUN gem install rails -v 8.0.0
|
24
23
|
RUN gem install rspec-rails
|
25
24
|
RUN rails new .
|
26
25
|
|
@@ -31,6 +30,7 @@ RUN bundle install
|
|
31
30
|
RUN rails generate rspec:install
|
32
31
|
|
33
32
|
COPY fake_spec_res/routes.rb /app/config/
|
33
|
+
COPY fake_spec_res/config/rails_spotlight.yml /app/config/
|
34
34
|
COPY fake_spec_res/dummy_controller.rb /app/app/controllers/
|
35
35
|
COPY fake_spec_res/dummy /app/app/views/dummy
|
36
36
|
COPY fake_spec_res/rails_spotlight_spec.rb /app/spec/integration/
|
@@ -1,4 +1,4 @@
|
|
1
|
-
FROM ruby:2.
|
1
|
+
FROM ruby:3.2.2-alpine
|
2
2
|
|
3
3
|
RUN apk add --update --no-cache \
|
4
4
|
build-base \
|
@@ -11,17 +11,17 @@ RUN apk add --update --no-cache \
|
|
11
11
|
yaml-dev \
|
12
12
|
yarn \
|
13
13
|
zlib-dev \
|
14
|
-
gcompat
|
14
|
+
gcompat \
|
15
|
+
postgresql-dev
|
15
16
|
|
16
17
|
RUN mkdir /app /gem
|
17
18
|
WORKDIR /app
|
18
19
|
|
19
20
|
RUN bundle config set force_ruby_platform true
|
20
21
|
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
|
21
|
-
RUN gem update --system 3.2.3
|
22
22
|
RUN gem install bundler -v 2.4.6
|
23
|
-
RUN gem install rails -v
|
24
|
-
RUN gem install rspec-rails
|
23
|
+
RUN gem install rails -v 8.0.2
|
24
|
+
RUN gem install rspec-rails
|
25
25
|
RUN rails new .
|
26
26
|
|
27
27
|
COPY . /gem
|
@@ -31,8 +31,13 @@ RUN bundle install
|
|
31
31
|
RUN rails generate rspec:install
|
32
32
|
|
33
33
|
COPY fake_spec_res/routes.rb /app/config/
|
34
|
+
COPY fake_spec_res/config/rails_spotlight.yml /app/config/
|
34
35
|
COPY fake_spec_res/dummy_controller.rb /app/app/controllers/
|
35
36
|
COPY fake_spec_res/dummy /app/app/views/dummy
|
36
37
|
COPY fake_spec_res/rails_spotlight_spec.rb /app/spec/integration/
|
37
38
|
|
39
|
+
RUN bundle exec rails db:migrate
|
40
|
+
|
41
|
+
ENV PARALLEL_WORKERS 1
|
42
|
+
|
38
43
|
CMD ["bin/rake"]
|
data/README.md
CHANGED
@@ -4,8 +4,8 @@ Chrome extension [Rails Spotlight](https://chrome.google.com/webstore/detail/rai
|
|
4
4
|
|
5
5
|
## Support for
|
6
6
|
|
7
|
-
* Rails
|
8
|
-
* Ruby
|
7
|
+
* Rails 6+
|
8
|
+
* Ruby 3.1+
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
@@ -44,24 +44,47 @@ file will be created in `config/rails_spotlight.yml`
|
|
44
44
|
STORAGE_PATH: <%=Rails.root.join('tmp', 'data', 'rails_spotlight')%>
|
45
45
|
STORAGE_POOL_SIZE: 20
|
46
46
|
LOGGER: <%=Logger.new(Rails.root.join('log', 'rails_spotlight.log'))%>
|
47
|
+
|
48
|
+
# Security configuration
|
49
|
+
DATA_ACCESS_TOKEN: # prevent from unauthorized access to the data
|
50
|
+
RAILS_SPOTLIGHT_PROJECT:
|
51
|
+
|
52
|
+
# Prevent from processing and sending some data to the extension
|
47
53
|
MIDDLEWARE_SKIPPED_PATHS: []
|
48
54
|
NOT_ENCODABLE_EVENT_VALUES:
|
49
55
|
SKIP_RENDERED_IVARS: []
|
56
|
+
|
57
|
+
# Features
|
58
|
+
FILE_MANAGER_ENABLED: true
|
59
|
+
RUBOCOP_ENABLED: true
|
60
|
+
SQL_CONSOLE_ENABLED: true
|
61
|
+
IRB_CONSOLE_ENABLED: true
|
62
|
+
|
63
|
+
# File manager configuration
|
50
64
|
BLOCK_EDITING_FILES: false
|
51
65
|
BLOCK_EDITING_FILES_OUTSIDE_OF_THE_PROJECT: true
|
52
66
|
DIRECTORY_INDEX_IGNORE: ['/.git', '**/*.lock', '**/.DS_Store', '/app/assets/images/**', '/app/assets/fonts/**', '/app/assets/builds/**']
|
67
|
+
|
68
|
+
# Rubocop configuration
|
53
69
|
RUBOCOP_CONFIG_PATH: '.rubocop.yml'
|
54
|
-
|
55
|
-
|
56
|
-
|
70
|
+
|
71
|
+
# Workarounds of CSP restrictions for form JS execution from the extension
|
72
|
+
FORM_JS_EXECUTION_TOKEN: <%= Digest::MD5.hexdigest(Rails.application.class.respond_to?(:module_parent_name) ? Rails.application.class.module_parent_name : Rails.application.class.parent_name)%>
|
73
|
+
|
57
74
|
# Required for all action cable features
|
58
|
-
|
59
|
-
|
75
|
+
USE_CABLE: false
|
76
|
+
|
77
|
+
# Rest of the configuration is required for ActionCable. It will be disabled automatically in when ActionCable is not available.
|
78
|
+
AUTO_MOUNT_CABLE: false
|
79
|
+
CABLE_MOUNT_PATH: /cable
|
80
|
+
|
60
81
|
# Experimental feature.
|
61
|
-
|
62
|
-
LIVE_LOGS_ENABLED: false
|
82
|
+
CABLE_LOGS_ENABLED: false
|
63
83
|
DEFAULT_RS_SRC: default
|
64
|
-
|
84
|
+
|
85
|
+
CABLE_CONSOLE_ENABLED: false
|
86
|
+
|
87
|
+
REQUEST_COMPLETED_BROADCAST_ENABLED: false
|
65
88
|
```
|
66
89
|
|
67
90
|
## Additional metrics
|
@@ -69,7 +92,7 @@ file will be created in `config/rails_spotlight.yml`
|
|
69
92
|
To enable additional rendering metrics like local variables, instance variables, params etc. add to your layout file:
|
70
93
|
|
71
94
|
```erb
|
72
|
-
<% if Rails.env.development? %>
|
95
|
+
<% if Rails.env.development? && defined?(::RailsSpotlight)%>
|
73
96
|
<%= RailsSpotlight::RenderViewReporter.report_rendered_view_locals(self, locals: local_assigns, params: params, skip_vars: %i[current_template], metadata: { just_test: 'Works' }) %>
|
74
97
|
<% end %>
|
75
98
|
```
|
@@ -77,8 +100,8 @@ To enable additional rendering metrics like local variables, instance variables,
|
|
77
100
|
## Experimental features
|
78
101
|
Live logs requires action cable to be enabled.
|
79
102
|
|
80
|
-
|
81
|
-
|
103
|
+
USE_CABLE: true
|
104
|
+
CABLE_LOGS_ENABLED: true
|
82
105
|
|
83
106
|
When you want to use different sources for the cable logs you need to update `cable.yml` file.
|
84
107
|
|
@@ -127,10 +150,10 @@ Known issue:
|
|
127
150
|
|
128
151
|
Authentication error when using:
|
129
152
|
- Specific authentication method and action cable
|
130
|
-
-
|
153
|
+
- AUTO_MOUNT_CABLE: true
|
131
154
|
|
132
155
|
Solution:
|
133
|
-
- Set
|
156
|
+
- Set AUTO_MOUNT_CABLE: false
|
134
157
|
- Add manually `mount ActionCable.server => '/cable'` to `config/routes.rb` with proper authentication method
|
135
158
|
|
136
159
|
---
|
@@ -141,6 +164,15 @@ Solution:
|
|
141
164
|
- Switch flag off
|
142
165
|
- REQUEST_COMPLETED_BROADCAST_ENABLED: false
|
143
166
|
|
167
|
+
---
|
168
|
+
|
169
|
+
SQL manager query execution freeze
|
170
|
+
|
171
|
+
It may happen in rail 8
|
172
|
+
|
173
|
+
Solution:
|
174
|
+
- Use `Execute query with write access toggle` to skip transactional/cancellable execution -> 
|
175
|
+
|
144
176
|
## Testing
|
145
177
|
|
146
178
|
To run tests for all versions of Rails and Ruby, run:
|
data/docker-compose.yml
CHANGED
@@ -1,16 +1,9 @@
|
|
1
|
-
version: '3.7'
|
2
1
|
services:
|
3
2
|
rubocop:
|
4
3
|
env_file:
|
5
4
|
- 'docker-variables.env'
|
6
5
|
build: .
|
7
6
|
command: bundle exec rubocop
|
8
|
-
spec-rails-5.2:
|
9
|
-
env_file:
|
10
|
-
- 'docker-variables.env'
|
11
|
-
build:
|
12
|
-
context: .
|
13
|
-
dockerfile: Dockerfile-rails-5.2
|
14
7
|
spec-rails-6.0:
|
15
8
|
env_file:
|
16
9
|
- 'docker-variables.env'
|
@@ -23,9 +16,21 @@ services:
|
|
23
16
|
build:
|
24
17
|
context: .
|
25
18
|
dockerfile: Dockerfile-rails-6.1
|
26
|
-
spec-rails-7.
|
19
|
+
spec-rails-7.1:
|
20
|
+
env_file:
|
21
|
+
- 'docker-variables.env'
|
22
|
+
build:
|
23
|
+
context: .
|
24
|
+
dockerfile: Dockerfile-rails-7.1
|
25
|
+
spec-rails-8.0:
|
26
|
+
env_file:
|
27
|
+
- 'docker-variables.env'
|
28
|
+
build:
|
29
|
+
context: .
|
30
|
+
dockerfile: Dockerfile-rails-8.0
|
31
|
+
spec-rails-8.0.2:
|
27
32
|
env_file:
|
28
33
|
- 'docker-variables.env'
|
29
34
|
build:
|
30
35
|
context: .
|
31
|
-
dockerfile: Dockerfile-rails-
|
36
|
+
dockerfile: Dockerfile-rails-8.0.2
|
Binary file
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Default configuration for RailsSpotlight
|
2
|
+
PROJECT_NAME: <%=Rails.application.class.respond_to?(:module_parent_name) ? Rails.application.class.module_parent_name : Rails.application.class.parent_name%>
|
3
|
+
SOURCE_PATH: <%=Rails.root%>
|
4
|
+
STORAGE_PATH: <%=Rails.root.join('tmp', 'data', 'rails_spotlight')%>
|
5
|
+
STORAGE_POOL_SIZE: 20
|
6
|
+
LOGGER: <%=Logger.new(Rails.root.join('log', 'rails_spotlight.log'))%>
|
7
|
+
|
8
|
+
# Security configuration
|
9
|
+
DATA_ACCESS_TOKEN: # prevent from unauthorized access to the data
|
10
|
+
RAILS_SPOTLIGHT_PROJECT:
|
11
|
+
|
12
|
+
# Prevent from processing and sending some data to the extension
|
13
|
+
MIDDLEWARE_SKIPPED_PATHS: []
|
14
|
+
NOT_ENCODABLE_EVENT_VALUES:
|
15
|
+
SKIP_RENDERED_IVARS: []
|
16
|
+
|
17
|
+
# Features
|
18
|
+
FILE_MANAGER_ENABLED: true
|
19
|
+
RUBOCOP_ENABLED: true
|
20
|
+
SQL_CONSOLE_ENABLED: true
|
21
|
+
IRB_CONSOLE_ENABLED: true
|
22
|
+
|
23
|
+
# File manager configuration
|
24
|
+
BLOCK_EDITING_FILES: false
|
25
|
+
BLOCK_EDITING_FILES_OUTSIDE_OF_THE_PROJECT: true
|
26
|
+
DIRECTORY_INDEX_IGNORE: ['/.git', '**/*.lock', '**/.DS_Store', '/app/assets/images/**', '/app/assets/fonts/**', '/app/assets/builds/**']
|
27
|
+
|
28
|
+
# Rubocop configuration
|
29
|
+
RUBOCOP_CONFIG_PATH: '.rubocop.yml'
|
30
|
+
|
31
|
+
# Workarounds of CSP restrictions for form JS execution from the extension
|
32
|
+
FORM_JS_EXECUTION_TOKEN: <%= Digest::MD5.hexdigest(Rails.application.class.respond_to?(:module_parent_name) ? Rails.application.class.module_parent_name : Rails.application.class.parent_name)%>
|
33
|
+
|
34
|
+
# Required for all action cable features
|
35
|
+
USE_CABLE: false
|
36
|
+
|
37
|
+
# Rest of the configuration is required for ActionCable. It will be disabled automatically in when ActionCable is not available.
|
38
|
+
AUTO_MOUNT_CABLE: false
|
39
|
+
CABLE_MOUNT_PATH: /cable
|
40
|
+
|
41
|
+
# Experimental feature.
|
42
|
+
CABLE_LOGS_ENABLED: false
|
43
|
+
DEFAULT_RS_SRC: default
|
44
|
+
|
45
|
+
CABLE_CONSOLE_ENABLED: false
|
46
|
+
|
47
|
+
REQUEST_COMPLETED_BROADCAST_ENABLED: false
|
@@ -6,7 +6,9 @@ require 'fileutils'
|
|
6
6
|
RSpec.describe DummyController, type: :request do # rubocop:disable Metrics/BlockLength
|
7
7
|
context 'rails_spotlight' do
|
8
8
|
it 'serve a file source' do
|
9
|
-
post '/__rails_spotlight/file.json',
|
9
|
+
post '/__rails_spotlight/file.json',
|
10
|
+
params: { file: 'config/application.rb', mode: :read }.to_json,
|
11
|
+
headers: { 'CONTENT_TYPE' => 'application/json' }
|
10
12
|
|
11
13
|
expect(response).to be_successful
|
12
14
|
expect(response.body).to include('# Require the gems listed in Gemfile, including any gems')
|
@@ -18,20 +20,36 @@ RSpec.describe DummyController, type: :request do # rubocop:disable Metrics/Bloc
|
|
18
20
|
File.write(Rails.root.join(file), 'OLD')
|
19
21
|
expect(File.read(Rails.root.join(file))).to_not eq content
|
20
22
|
|
21
|
-
post '/__rails_spotlight/file.json',
|
23
|
+
post '/__rails_spotlight/file.json',
|
24
|
+
params: { file: file, mode: :write, content: content }.to_json,
|
25
|
+
headers: { 'CONTENT_TYPE' => 'application/json' }
|
22
26
|
|
23
27
|
expect(response).to be_successful
|
24
|
-
expect(response.body).to eq({
|
28
|
+
expect(response.body).to eq({
|
29
|
+
source: content,
|
30
|
+
changed: true,
|
31
|
+
in_project: true,
|
32
|
+
relative_path: file,
|
33
|
+
root_path: '/app',
|
34
|
+
new_content: content,
|
35
|
+
project: 'App'
|
36
|
+
}.to_json)
|
37
|
+
|
25
38
|
expect(File.read(Rails.root.join(file))).to eq content
|
26
39
|
end
|
27
40
|
|
28
41
|
it 'serve a verify info' do
|
29
|
-
|
42
|
+
body = { test: 'ok' }.to_json
|
43
|
+
post '/__rails_spotlight/verify.json?check=yes',
|
44
|
+
params: body,
|
45
|
+
headers: { 'CONTENT_TYPE' => 'application/json', 'HTTP_X_RAILS_SPOTLIGHT' => '1.0.0' }
|
30
46
|
expect(response).to be_successful
|
31
47
|
end
|
32
48
|
|
33
49
|
it 'serve a sql result' do
|
34
|
-
post '/__rails_spotlight/sql.json',
|
50
|
+
post '/__rails_spotlight/sql.json',
|
51
|
+
params: { query: 'select sqlite_version();' }.to_json,
|
52
|
+
headers: { 'CONTENT_TYPE' => 'application/json' }
|
35
53
|
expect(response).to be_successful
|
36
54
|
expect(JSON.parse(response.body).keys).to eq(%w[query result logs error query_mode project])
|
37
55
|
end
|
@@ -59,14 +59,13 @@ module RailsSpotlight
|
|
59
59
|
Event.new(name, start, ending, transaction_id, payload)
|
60
60
|
}
|
61
61
|
|
62
|
-
# Subscribe to all
|
63
|
-
#
|
62
|
+
# Subscribe to all relevant events
|
64
63
|
def self.subscribe
|
65
64
|
# Skip RailsSpotlight subscriptions during migrations
|
66
65
|
return if migrating?
|
67
66
|
|
68
67
|
new
|
69
|
-
.subscribe('rsl.notification.log')
|
68
|
+
# .subscribe('rsl.notification.log') # We do not publish events to this channel for now
|
70
69
|
.subscribe('sql.active_record', &SQL_BLOCK)
|
71
70
|
.subscribe('sql.sequel', &SQL_BLOCK)
|
72
71
|
.subscribe('render_partial.action_view', &VIEW_BLOCK)
|
@@ -5,7 +5,7 @@ require_relative '../../rails_command_executor'
|
|
5
5
|
module RailsSpotlight
|
6
6
|
module Channels
|
7
7
|
module Handlers
|
8
|
-
class
|
8
|
+
class ConsoleHandler
|
9
9
|
TYPE = 'console'
|
10
10
|
|
11
11
|
def initialize(data)
|
@@ -15,7 +15,7 @@ module RailsSpotlight
|
|
15
15
|
attr_reader :data
|
16
16
|
|
17
17
|
def call
|
18
|
-
return unless ::RailsSpotlight.config.
|
18
|
+
return unless ::RailsSpotlight.config.cable_logs_enabled?
|
19
19
|
return unless data['type'] == TYPE
|
20
20
|
|
21
21
|
command = data['command']
|
@@ -44,7 +44,7 @@ module RailsSpotlight
|
|
44
44
|
executor.execute(command)
|
45
45
|
if executor.execution_successful?
|
46
46
|
{
|
47
|
-
payload: { result: executor.result_as_json(inspect_types:
|
47
|
+
payload: { result: executor.result_as_json(inspect_types:) }
|
48
48
|
}
|
49
49
|
else
|
50
50
|
{
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'handlers/
|
3
|
+
require_relative 'handlers/console_handler'
|
4
4
|
require_relative 'handlers/logs_handler'
|
5
5
|
|
6
6
|
module RailsSpotlight
|
@@ -14,11 +14,11 @@ module RailsSpotlight
|
|
14
14
|
|
15
15
|
attr_reader :code
|
16
16
|
end
|
17
|
-
TYPES = [
|
17
|
+
TYPES = [ConsoleHandler::TYPE, LogsHandler::TYPE].freeze
|
18
18
|
|
19
19
|
def self.handle(data)
|
20
20
|
case data['type']
|
21
|
-
when
|
21
|
+
when ConsoleHandler::TYPE then ConsoleHandler.new(data).call
|
22
22
|
when LogsHandler::TYPE then LogsHandler.new(data).call
|
23
23
|
end
|
24
24
|
end
|
@@ -33,6 +33,25 @@ module RailsSpotlight
|
|
33
33
|
RailsSpotlight.config.logger.fatal("#{e.message}\n #{e.backtrace.join("\n ")}")
|
34
34
|
end
|
35
35
|
|
36
|
+
def self.broadcast_log(message, level, callsite = {}, name = nil) # rubocop:disable Metrics/CyclomaticComplexity
|
37
|
+
return unless ::RailsSpotlight.config.use_cable?
|
38
|
+
return if message.blank?
|
39
|
+
|
40
|
+
broadcast(
|
41
|
+
type: 'logs',
|
42
|
+
payload: (callsite || {}).merge(
|
43
|
+
msg: message,
|
44
|
+
src: ENV['RS_SRC'] || RailsSpotlight.config.default_rs_src,
|
45
|
+
l: level,
|
46
|
+
dt: Time.now.to_f,
|
47
|
+
id: AppRequest.current&.id,
|
48
|
+
pg: name
|
49
|
+
)
|
50
|
+
)
|
51
|
+
rescue StandardError => e
|
52
|
+
RailsSpotlight.config.logger.fatal("#{e.message}\n #{e.backtrace&.join("\n ")}")
|
53
|
+
end
|
54
|
+
|
36
55
|
def subscribed
|
37
56
|
stream_from ::RailsSpotlight::Channels::SPOTLIGHT_CHANNEL
|
38
57
|
publish({ message: "Your #{project} project is now connected to the spotlight channel.", code: :connected, type: :info })
|
@@ -54,7 +73,7 @@ module RailsSpotlight
|
|
54
73
|
private
|
55
74
|
|
56
75
|
def publish(data)
|
57
|
-
connection.transmit identifier: @identifier, message: data.merge(project
|
76
|
+
connection.transmit identifier: @identifier, message: data.merge(project:, version:)
|
58
77
|
# we do not use transmit because it is triggering logs and can cause an infinite loop
|
59
78
|
# transmit(data.merge(project: project, version: version))
|
60
79
|
end
|