rails_spotlight 0.2.0 → 0.2.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: df87e15beee1f5b3706be05e0e6642d56165eeb7ae667cab7dad6514abcfe728
4
- data.tar.gz: 50d7dc4b7cefae1cf565f021aea4d398757ff6a09bd5bdce3dd8e2b56ed24cee
3
+ metadata.gz: 41eb3756c5f0405d7811d039c0953ac3a62b993486a4fc2e2085686c8c9cd54b
4
+ data.tar.gz: fd0d5d64ff53a660ade6867f05c152e36cd228ccb02b1d9006c3e4be8ed8e6cd
5
5
  SHA512:
6
- metadata.gz: e5050e1f700b52d97e62cf26d1fc1cd37f2f5eb1fe5ffc815f030aea8a67e137b0eb4030aff8ca52c06586e754f327477a6ae93fe3502d2e876e2c6e61de9333
7
- data.tar.gz: 0ae4a9d1b8d806f0c8bc33297c3d941e683c4d7731a672a4804889a3700b65229fd2334a35ca94874ec0ba76a1a820a549ffddff05c8f651753ed6e6b6e32f27
6
+ metadata.gz: d3159584ad8395c2ea3a17fb969cd9a50c94a120c0db950ff11db8d52ce3357f443c7944a23dc8dc3521844f98e6cdc30da288f53a08e6308f8722c53a85907b
7
+ data.tar.gz: 2057d0386f21959a19b229ca2f3b4e46db2a0270d1c8f1262f551363eeda54c7127bc3b78c1c209b6e949a62dc2ce1c82989b17650eaa7c6dc02bb99874f3389
data/README.md CHANGED
@@ -45,6 +45,18 @@ file will be created in `config/rails_spotlight.yml`
45
45
  ACTION_CABLE_MOUNT_PATH: /cable
46
46
  ```
47
47
 
48
+ ## Troubleshooting
49
+
50
+ Known issue:
51
+
52
+ Authentication error when using:
53
+ - Specific authentication method and action cable
54
+ - AUTO_MOUNT_ACTION_CABLE: true
55
+
56
+ Solution:
57
+ - Set AUTO_MOUNT_ACTION_CABLE: false
58
+ - Add manually `mount ActionCable.server => '/cable'` to `config/routes.rb` with proper authentication method
59
+
48
60
  ## Testing
49
61
 
50
62
  To run tests for all versions of Rails and Ruby, run:
@@ -55,19 +67,9 @@ docker-compose up
55
67
 
56
68
  ## Usage
57
69
 
58
- ## Development
59
-
60
- ## Contributing
61
-
62
- Bug reports and pull requests are welcome on GitHub at https://github.com/pniemczyk/rails_spotlight. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rails_spotlight/blob/master/CODE_OF_CONDUCT.md).
70
+ Gem is created for the Chrome extension [Rails Spotlight](https://chrome.google.com/webstore/detail/rails-spotlight/kfacifkandemkdemkliponofajohhnbp?hl=en-US), but it can be used for any purpose.
63
71
 
64
72
  ## License
65
73
 
66
74
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
67
75
 
68
- ## Code of Conduct
69
-
70
- Everyone interacting in the RailsSpotlight project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pniemczyk/rails_spotlight/blob/master/CODE_OF_CONDUCT.md).
71
-
72
-
73
- check https://github.com/alexrudall/ruby-openai
@@ -19,11 +19,11 @@ module RailsSpotlight
19
19
  @logger = opts[:logger] || Logger.new(File.join(self.class.rails_root, 'log', 'rails_spotlight.log'))
20
20
  @storage_path = opts[:storage_path] || File.join(self.class.rails_root, 'tmp', 'data', 'rails_spotlight')
21
21
  @storage_pool_size = opts[:storage_pool_size] || 20
22
- @live_console_enabled = opts[:live_console_enabled] || true
23
- @request_completed_broadcast_enabled = opts[:request_completed_broadcast_enabled] || false
22
+ @live_console_enabled = opts[:live_console_enabled].nil? ? true : is_true?(opts[:live_console_enabled])
23
+ @request_completed_broadcast_enabled = is_true?(opts[:request_completed_broadcast_enabled])
24
24
  @middleware_skipped_paths = opts[:middleware_skipped_paths] || []
25
25
  @not_encodable_event_values = DEFAULT_NOT_ENCODABLE_EVENT_VALUES.merge(opts[:not_encodable_event_values] || {})
26
- @auto_mount_action_cable = opts[:auto_mount_action_cable] || true
26
+ @auto_mount_action_cable = opts[:auto_mount_action_cable].nil? ? true : is_true?(opts[:auto_mount_action_cable])
27
27
  @action_cable_mount_path = opts[:action_cable_mount_path] || '/cable'
28
28
  end
29
29
 
@@ -54,9 +54,10 @@ module RailsSpotlight
54
54
  return new unless File.exist?(config_file)
55
55
 
56
56
  erb_result = ERB.new(File.read(config_file)).result
57
- config = YAML.safe_load(erb_result) || {}
57
+ data = YAML.safe_load(erb_result) || {}
58
+
58
59
  # Support older versions of Ruby and Rails
59
- opts = config.each_with_object({}) do |(key, value), memo|
60
+ opts = data.each_with_object({}) do |(key, value), memo|
60
61
  new_key = key.is_a?(String) ? key.downcase.to_sym : key
61
62
  memo[new_key] = value
62
63
  end
@@ -74,6 +75,10 @@ module RailsSpotlight
74
75
 
75
76
  private
76
77
 
78
+ def is_true?(value)
79
+ value == true || value == 'true' || value == 1 || value == '1'
80
+ end
81
+
77
82
  def detect_project_name
78
83
  return ENV['RAILS_SPOTLIGHT_PROJECT'] if ENV['RAILS_SPOTLIGHT_PROJECT'].present?
79
84
 
@@ -63,30 +63,14 @@ module RailsSpotlight
63
63
  end
64
64
 
65
65
  def transform_hash(original, options = {}, &block)
66
- # options[:safe_descent] ||= {}
67
- # new_hash = {}
68
- # options[:safe_descent][original.object_id] = new_hash
69
- # original.each_with_object(new_hash) do |(key, value), result|
70
- # if options[:deep] && Hash === value
71
- # value = options[:safe_descent].fetch(value.object_id) do
72
- # transform_hash(value, options, &block)
73
- # end
74
- # end
75
- # block.call(result, key, value)
76
- # end
77
-
78
- # Initialize safe_descent hash to keep track of hashes already transformed.
79
- # options[:safe_descent] ||= {}
80
66
  options[:safe_descent] ||= {}.compare_by_identity
81
67
 
82
68
  # Check if the hash has already been transformed to prevent infinite recursion.
83
- # return options[:safe_descent][original.object_id] if options[:safe_descent].key?(original.object_id)
84
69
  return options[:safe_descent][original] if options[:safe_descent].key?(original)
85
70
 
86
71
  # Create a new hash to store the transformed values.
87
72
  new_hash = {}
88
73
  # Store the new hash in safe_descent using the original's object_id to mark it as processed.
89
- # options[:safe_descent][original.object_id] = new_hash
90
74
  options[:safe_descent][original] = new_hash
91
75
 
92
76
  # Iterate over each key-value pair in the original hash.
@@ -94,7 +78,6 @@ module RailsSpotlight
94
78
  # If deep transformation is required and the value is a hash,
95
79
  # recursively transform it, unless it's already been transformed.
96
80
  if options[:deep] && Hash === value # rubocop:disable Style/CaseEquality
97
- # value = options[:safe_descent].fetch(value.object_id) do
98
81
  value = options[:safe_descent].fetch(value) do
99
82
  transform_hash(value, options, &block)
100
83
  end
@@ -5,7 +5,7 @@ require 'rails/railtie'
5
5
  module RailsSpotlight
6
6
  class Railtie < ::Rails::Railtie
7
7
  initializer 'rails_spotlight.inject_middlewares' do
8
- insert_middleware unless Rails.env.production?
8
+ insert_base_middlewares unless Rails.env.production?
9
9
  end
10
10
 
11
11
  initializer 'rails_spotlight.log_interceptor' do
@@ -17,19 +17,28 @@ module RailsSpotlight
17
17
  end
18
18
 
19
19
  initializer 'rails_spotlight.action_cable_setup' do
20
- unless Rails.env.production?
21
- app.config.after_initialize do
22
- existing_origins = Array(app.config.action_cable.allowed_request_origins)
23
- app.config.action_cable.allowed_request_origins = existing_origins | [%r{\Achrome-extension://.*\z}]
24
-
25
- require 'rails_spotlight/channels/request_completed_channel' if ::RailsSpotlight.config.request_completed_broadcast_enabled?
26
- require 'rails_spotlight/channels/live_console_channel' if ::RailsSpotlight.config.live_console_enabled?
27
- Rails.application.routes.draw { mount ActionCable.server => '/cable' } if ::RailsSpotlight.config.auto_mount_action_cable?
28
- end
20
+ insert_action_cable_helpers unless Rails.env.production?
21
+ end
22
+
23
+ def insert_action_cable_helpers
24
+ return unless ::RailsSpotlight.config.action_cable_present?
25
+
26
+ app.config.after_initialize do
27
+ update_actioncable_allowed_request_origins!
28
+
29
+ require 'rails_spotlight/channels/request_completed_channel' if ::RailsSpotlight.config.request_completed_broadcast_enabled?
30
+ require 'rails_spotlight/channels/live_console_channel' if ::RailsSpotlight.config.live_console_enabled?
31
+
32
+ app.routes.draw { mount ActionCable.server => '/cable' } if ::RailsSpotlight.config.auto_mount_action_cable?
29
33
  end
30
34
  end
31
35
 
32
- def insert_middleware
36
+ def update_actioncable_allowed_request_origins!
37
+ existing_origins = Array(app.config.action_cable.allowed_request_origins)
38
+ app.config.action_cable.allowed_request_origins = existing_origins | [%r{\Achrome-extension://.*\z}]
39
+ end
40
+
41
+ def insert_base_middlewares
33
42
  app.middleware.use ::RailsSpotlight::Middlewares::RequestHandler
34
43
 
35
44
  if defined? ActionDispatch::DebugExceptions
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsSpotlight
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pawel Niemczyk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-28 00:00:00.000000000 Z
11
+ date: 2024-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-contrib