rails_spotlight 0.5.0 → 0.5.1

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97fa9dc74cea28532602f60c83e5dd0c5ca79f6bd63ad68f8d1b1cd84a5ce0b7
4
- data.tar.gz: 002f2d9081c6877a6c569f49db2f17e2fcb02d4cc2800e0a69cff5375c89ab2f
3
+ metadata.gz: ed7177dae7290c4108d3f82dbe6705449358e3b8805219b6780e93924547419e
4
+ data.tar.gz: e4c0c873e82299d1637e43ef0c844c4444150677b24881ab570e508023f154e2
5
5
  SHA512:
6
- metadata.gz: 637f0d742d42129342fc6733a823e72c2fdf9f00c627dd137f78f2f7b0801108c5c522c208123383139f84335e6d02c3e3493efd986b0bd328e8097f7d769678
7
- data.tar.gz: 80eac812bd515eda62d6ed28123b114b287e35b8467542837ef789fda7f43498f2188227ec5c3eb8959691d4b6d0b70d7279fe9b2b166fec2b48d18c92df8921
6
+ metadata.gz: 0d04a55bf3d180539e32f12dd183ee910e94a543ce81c416dd14b8d9d027ee271bbb099071c8c3b9e921303d14e3d4e4b026619e73ef44b17f762c4e045b54a4
7
+ data.tar.gz: d0dd1ccb93add3a50cb773d9cc4019aac268363f673a688a8b1c6aea39b33eceea61eee51e8f656a49798e9213b8a2d1c76661a0b2ffe3d3d7301e681149b36d
data/README.md CHANGED
@@ -38,6 +38,7 @@ file will be created in `config/rails_spotlight.yml`
38
38
  ### Configuration options
39
39
 
40
40
  ```yaml
41
+ ENABLED: true
41
42
  # Default configuration for RailsSpotlight
42
43
  PROJECT_NAME: <%=Rails.application.class.respond_to?(:module_parent_name) ? Rails.application.class.module_parent_name : Rails.application.class.parent_name%>
43
44
  SOURCE_PATH: <%=Rails.root%>
@@ -143,7 +144,6 @@ You can add to your Initializers `config/initializers/rails_spotlight.rb` file w
143
144
  end
144
145
  ```
145
146
 
146
-
147
147
  ## Troubleshooting
148
148
 
149
149
  Known issue:
@@ -1,3 +1,4 @@
1
+ ENABLED: true
1
2
  # Default configuration for RailsSpotlight
2
3
  PROJECT_NAME: <%=Rails.application.class.respond_to?(:module_parent_name) ? Rails.application.class.module_parent_name : Rails.application.class.parent_name%>
3
4
  SOURCE_PATH: <%=Rails.root%>
@@ -15,6 +16,7 @@
15
16
  SKIP_RENDERED_IVARS: []
16
17
 
17
18
  # Features
19
+ LOGS_ENABLED: true
18
20
  FILE_MANAGER_ENABLED: true
19
21
  RUBOCOP_ENABLED: true
20
22
  SQL_CONSOLE_ENABLED: true
@@ -40,13 +40,15 @@ module RailsSpotlight
40
40
  @devise_mapping
41
41
  ].freeze
42
42
 
43
- attr_reader :project_name, :source_path, :logger, :storage_path, :storage_pool_size, :middleware_skipped_paths,
44
- :not_encodable_event_values, :cable_mount_path,
43
+ attr_reader :enabled, :project_name, :source_path, :logger, :storage_path, :storage_pool_size, :middleware_skipped_paths,
44
+ :not_encodable_event_values, :cable_mount_path, :logs_enabled,
45
45
  :file_manager_enabled, :block_editing_files, :block_editing_files_outside_of_the_project, :skip_rendered_ivars,
46
46
  :directory_index_ignore, :rubocop_enabled, :rubocop_config_path, :use_cable, :default_rs_src,
47
47
  :form_js_execution_token, :sql_console_enabled, :irb_console_enabled, :data_access_token
48
48
 
49
49
  def initialize(opts = {}) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
50
+ @enabled = bool_val(:enabled, opts, default: false)
51
+ @logs_enabled = bool_val(:logs_enabled, opts, default: true)
50
52
  @project_name = opts[:project_name] || detect_project_name
51
53
  @source_path = opts[:source_path] || self.class.rails_root
52
54
  @logger = opts[:logger] || Logger.new(File.join(self.class.rails_root, 'log', 'rails_spotlight.log'))
@@ -80,6 +82,8 @@ module RailsSpotlight
80
82
  def auto_mount_cable = @auto_mount_cable && use_cable && action_cable_present?
81
83
  def action_cable_present? = defined?(ActionCable) && true
82
84
 
85
+ alias enabled? enabled
86
+ alias logs_enabled? logs_enabled
83
87
  alias cable_console_enabled? cable_console_enabled
84
88
  alias cable_logs_enabled? cable_logs_enabled
85
89
  alias use_cable? use_cable
@@ -38,9 +38,9 @@ module RailsSpotlight
38
38
 
39
39
  private
40
40
 
41
- def _skip_logging?(message)
41
+ def _skip_cable_logging?(message)
42
42
  return false unless ::RailsSpotlight.config.use_cable?
43
- return false unless message.is_a?(String)
43
+ return false unless ActionCable.server.config&.cable&.dig(:adapter).present?
44
44
 
45
45
  message.include?(::RailsSpotlight::Channels::SPOTLIGHT_CHANNEL)
46
46
  end
@@ -60,13 +60,14 @@ module RailsSpotlight
60
60
  end
61
61
  end
62
62
 
63
- return if _skip_logging?(message)
63
+ return unless message.is_a?(String)
64
64
 
65
65
  callsite = Utils.dev_callsite(caller.drop(1))
66
66
  name = progname.is_a?(String) || progname.is_a?(Symbol) ? progname : nil
67
- message = yield if message.nil? && block_given?
68
67
 
69
68
  AppRequest.current.events << Event.new('rsl.notification.log', 0, 0, 0, (callsite || {}).merge(message:, level: severity, progname: name)) if AppRequest.current
69
+ return if _skip_cable_logging?(message)
70
+
70
71
  ::RailsSpotlight::Channels::SpotlightChannel.broadcast_log(message, level, callsite, name)
71
72
  rescue StandardError => e
72
73
  RailsSpotlight.config.logger.fatal("#{e.message}\n #{e.backtrace&.join("\n ")}")
@@ -3,7 +3,7 @@
3
3
  module RailsSpotlight
4
4
  module Middlewares
5
5
  module SkipRequestPaths
6
- PATHS_TO_SKIP = %w[/__better_errors /__rails_spotlight /__meta_request].freeze
6
+ PATHS_TO_SKIP = %w[/__better_errors /__rails_spotlight /__meta_request /rails].freeze
7
7
 
8
8
  private
9
9
 
@@ -15,8 +15,10 @@ module RailsSpotlight
15
15
 
16
16
  def call(env)
17
17
  request_path = env['PATH_INFO']
18
+ return app.call(env) if skip?(request_path)
19
+
18
20
  middleware = Rack::ResponseHeaders.new(app) do |headers|
19
- headers['X-Rails-Spotlight-Version'] = RailsSpotlight::VERSION unless skip?(request_path)
21
+ headers['X-Rails-Spotlight-Version'] = RailsSpotlight::VERSION
20
22
  end
21
23
  middleware.call(env)
22
24
  end
@@ -25,7 +27,7 @@ module RailsSpotlight
25
27
 
26
28
  attr_reader :app, :app_config
27
29
 
28
- def default_skip_paths = %w[/__better_errors /__meta_request]
30
+ def default_skip_paths = %w[/__better_errors /__meta_request /rails]
29
31
  end
30
32
  end
31
33
  end
@@ -14,15 +14,12 @@ module RailsSpotlight
14
14
  end
15
15
 
16
16
  def call(env)
17
+ return app.call(env) if skip?(env['PATH_INFO']) || (env['HTTP_CONNECTION'] == 'Upgrade' && env['HTTP_UPGRADE'] == 'websocket')
17
18
  return app.call(env) unless ::RailsSpotlight.config.request_completed_broadcast_enabled?
18
19
 
19
- if skip?(env['PATH_INFO']) || (env['HTTP_CONNECTION'] == 'Upgrade' && env['HTTP_UPGRADE'] == 'websocket')
20
- app.call(env)
21
- else
22
- status, headers, body = app.call(env)
23
- publish_event(status, headers, env)
24
- [status, headers, body]
25
- end
20
+ status, headers, body = app.call(env)
21
+ publish_event(status, headers, env)
22
+ [status, headers, body]
26
23
  rescue => e # rubocop:disable Style/RescueStandardError
27
24
  ::RailsSpotlight.config.logger.error "Error in RailsSpotlight::Middlewares::RequestCompletedHandler instrumentation: #{e.message}"
28
25
  app.call(env)
@@ -6,22 +6,29 @@ require_relative 'log_interceptor'
6
6
  module RailsSpotlight
7
7
  class Railtie < ::Rails::Railtie
8
8
  initializer 'rails_spotlight.inject_middlewares' do
9
- insert_base_middlewares unless Rails.env.production?
9
+ next unless ::RailsSpotlight.config.enabled?
10
+
11
+ insert_base_middlewares
10
12
  end
11
13
 
12
14
  initializer 'rails_spotlight.log_interceptor' do
13
- unless Rails.env.production?
14
- Rails.logger&.extend(LogInterceptor)
15
- defined?(Sidekiq::Logger) && Sidekiq.logger&.extend(LogInterceptor)
16
- end
15
+ next unless ::RailsSpotlight.config.enabled?
16
+ next unless ::RailsSpotlight.config.logs_enabled?
17
+
18
+ Rails.logger&.extend(LogInterceptor)
19
+ defined?(Sidekiq::Logger) && Sidekiq.logger&.extend(LogInterceptor)
17
20
  end
18
21
 
19
22
  initializer 'rails_spotlight.subscribe_to_notifications' do
20
- AppNotifications.subscribe unless Rails.env.production?
23
+ next unless ::RailsSpotlight.config.enabled?
24
+
25
+ AppNotifications.subscribe
21
26
  end
22
27
 
23
28
  initializer 'rails_spotlight.action_cable_setup' do
24
- insert_action_cable_helpers unless Rails.env.production?
29
+ next unless ::RailsSpotlight.config.enabled?
30
+
31
+ insert_action_cable_helpers
25
32
  end
26
33
 
27
34
  def insert_action_cable_helpers
@@ -53,6 +60,7 @@ module RailsSpotlight
53
60
  app.middleware.use ::RailsSpotlight::Middlewares::MainRequestHandler
54
61
 
55
62
  return unless ::RailsSpotlight.config.request_completed_broadcast_enabled?
63
+ return unless ActionCable.server.config&.cable&.dig(:adapter).present?
56
64
 
57
65
  # app.middleware.insert_after ::RailsSpotlight::Middlewares::HeaderMarker, RailsSpotlight::Middlewares::RequestCompleted, app.config
58
66
  if defined? ActionDispatch::Executor
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsSpotlight
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
data/lib/tasks/init.rake CHANGED
@@ -10,6 +10,7 @@ namespace :rails_spotlight do # rubocop:disable Metrics/BlockLength
10
10
  config_path = Rails.root.join('config', 'rails_spotlight.yml')
11
11
 
12
12
  default_config = <<~YAML
13
+ ENABLED: true
13
14
  # Default configuration for RailsSpotlight
14
15
  PROJECT_NAME: <%=Rails.application.class.respond_to?(:module_parent_name) ? Rails.application.class.module_parent_name : Rails.application.class.parent_name%>
15
16
  SOURCE_PATH: <%=Rails.root%>
@@ -27,6 +28,7 @@ namespace :rails_spotlight do # rubocop:disable Metrics/BlockLength
27
28
  SKIP_RENDERED_IVARS: []
28
29
 
29
30
  # Features
31
+ LOGS_ENABLED: true
30
32
  FILE_MANAGER_ENABLED: true
31
33
  RUBOCOP_ENABLED: true
32
34
  SQL_CONSOLE_ENABLED: true
@@ -123,9 +125,9 @@ namespace :rails_spotlight do # rubocop:disable Metrics/BlockLength
123
125
 
124
126
  case layout_format
125
127
  when 'slim', 'haml'
126
- puts "- if Rails.env.development?\n = render 'layouts/#{partial_name.split('.').first}'" # rubocop:disable Style/StringLiteralsInInterpolation
128
+ puts "- if defined?(RailsSpotlight) && Rails.env.development?\n = render 'layouts/#{partial_name.split('.').first}'" # rubocop:disable Style/StringLiteralsInInterpolation
127
129
  else
128
- puts "<% if Rails.env.development? %>\n <%= render 'layouts/#{partial_name.split('.').first}' %>\n<% end %>" # rubocop:disable Style/StringLiteralsInInterpolation
130
+ puts "<% if defined?(RailsSpotlight) && Rails.env.development? %>\n <%= render 'layouts/#{partial_name.split('.').first}' %>\n<% end %>" # rubocop:disable Style/StringLiteralsInInterpolation
129
131
  end
130
132
  end
131
133
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_spotlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pawel Niemczyk
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-16 00:00:00.000000000 Z
10
+ date: 2025-04-14 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rack-contrib