rails_spotlight 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 204e34e484ceb524e16c2a2e122f37d036d715e418b52c7554fb241e4808b5c9
4
- data.tar.gz: c89021305a1e1dd5d07e47e06ff85af329a69bd66640db326a755441c6969978
3
+ metadata.gz: 797f782446bb2946abfc23b500dd6bed6032df02be0795e0d44083ca78344d19
4
+ data.tar.gz: a95afda90830aaa9520b1f88012091a3481ca6ac71fd031fda5f4e8dddd8b126
5
5
  SHA512:
6
- metadata.gz: e868e72afc9da1d88c1b3f7560410b8609f15929b24bb74381461b7723374369823b70b651d2d6ac137ab24db53d00997cb6de825a4f9901c6b2688b4904e80e
7
- data.tar.gz: 333b0548005715899d6cba9729b50ef37a2604ea6f6939cd3bba6807db2dce788460a502ff25e3121879203ac56033050d871b90f3f8778a36925d157b51de72
6
+ metadata.gz: a5a44dc240578e5a9a639a666d6adcb5bee447e46d26af4d6f2fd3e8e1c1c39bb9129f1df13ca209a525a16413584e2a06405c1392e652c882d671389533524a
7
+ data.tar.gz: 047e4a531ef327f471a494d0865be7b2d2327572bfda8c5575638b62ebf768ab66d34c497177c3cf9b04586df6f95cace25ac234525acba17cea8d56c7a2ef0f
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 5+
8
- Ruby 2.6+
7
+ * Rails 5+
8
+ * Ruby 2.6+
9
9
 
10
10
  ## Installation
11
11
 
@@ -17,6 +17,14 @@ group :development do
17
17
  end
18
18
  ```
19
19
 
20
+ ## Configuration
21
+
22
+ environment variables
23
+
24
+ ```
25
+ RAILS_SPOTLIGHT_PROJECT=MyProjectName
26
+ ```
27
+
20
28
  ## Testing
21
29
 
22
30
  To run tests for all versions of Rails and Ruby, run:
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../../support/project'
4
+
3
5
  module RailsSpotlight
4
6
  module Middlewares
5
7
  module Handlers
@@ -19,7 +21,10 @@ module RailsSpotlight
19
21
  end
20
22
 
21
23
  def json_response_body
22
- { source: text_response_body }
24
+ {
25
+ source: text_response_body,
26
+ project: ::RailsSpotlight::Support::Project.instance.name
27
+ }
23
28
  end
24
29
 
25
30
  def write_mode?
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../../support/project'
4
+
3
5
  module RailsSpotlight
4
6
  module Middlewares
5
7
  module Handlers
@@ -8,22 +10,41 @@ module RailsSpotlight
8
10
  if ActiveSupport.const_defined?('ExecutionContext')
9
11
  ActiveSupport::Notifications.subscribed(method(:logger), 'sql.active_record', monotonic: true) do
10
12
  ActiveSupport::ExecutionContext.set(rails_spotlight: request_id) do
11
- self.result = ActiveRecord::Base.connection.exec_query(query)
13
+ transaction
12
14
  end
13
15
  end
14
16
  else
15
17
  ActiveSupport::Notifications.subscribed(method(:logger), 'sql.active_record') do
16
- self.result = ActiveRecord::Base.connection.exec_query(query)
18
+ transaction
17
19
  end
18
20
  end
19
21
  end
20
22
 
21
23
  private
22
24
 
25
+ def transaction
26
+ ActiveRecord::Base.transaction do
27
+ begin
28
+ self.result = ActiveRecord::Base.connection.exec_query(query)
29
+ rescue => e
30
+ self.error = e
31
+ ensure
32
+ raise ActiveRecord::Rollback unless force_execution?
33
+ end
34
+ end
35
+ end
36
+
23
37
  attr_accessor :result
38
+ attr_accessor :error
24
39
 
25
40
  def json_response_body
26
- { result: result, logs: logs }
41
+ {
42
+ result: result,
43
+ logs: logs,
44
+ error: error.inspect,
45
+ query_mode: force_execution? ? 'force' : 'default',
46
+ project: ::RailsSpotlight::Support::Project.instance.name
47
+ }
27
48
  end
28
49
 
29
50
  def logger(_, started, finished, unique_id, payload)
@@ -39,6 +60,10 @@ module RailsSpotlight
39
60
  def query
40
61
  @query ||= json_request_body.fetch('query')
41
62
  end
63
+
64
+ def force_execution?
65
+ @force_execution ||= json_request_body['mode'] == 'force'
66
+ end
42
67
  end
43
68
  end
44
69
  end
@@ -0,0 +1,19 @@
1
+ module RailsSpotlight
2
+ module Support
3
+ class Project
4
+ include Singleton
5
+
6
+ def name
7
+ @name ||= ENV['RAILS_SPOTLIGHT_PROJECT'] || if app_class.respond_to?(:module_parent_name)
8
+ app_class.module_parent_name
9
+ else
10
+ app_class.parent_name
11
+ end
12
+ end
13
+
14
+ def app_class
15
+ @app_class ||= Rails.application.class
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsSpotlight
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_spotlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pawel Niemczyk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-21 00:00:00.000000000 Z
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-contrib
@@ -187,6 +187,7 @@ files:
187
187
  - lib/rails_spotlight/middlewares/handlers/verify_action_handler.rb
188
188
  - lib/rails_spotlight/middlewares/request_handler.rb
189
189
  - lib/rails_spotlight/railtie.rb
190
+ - lib/rails_spotlight/support/project.rb
190
191
  - lib/rails_spotlight/version.rb
191
192
  - sig/rails_spotlight.rbs
192
193
  homepage: https://github.com/pniemczyk/rails_spotlight