Skip to content

Commit b840aed

Browse files
ndbroadbentclaude
andcommitted
Fix storage field type conversions in integrations
Convert storage fields to Symbol type in: - ActiveStorage: service_name.to_sym instead of .to_s - CarrierWave: Extract storage type from class name and convert to symbol - Shrine: Ensure payload[:storage] is always a symbol This fixes Rails integration test failures where storage names were being passed as Strings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 01a4973 commit b840aed

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

lib/log_struct/integrations/active_storage.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def self.process_active_storage_event(event, config)
7171
log_data = case event_type
7272
when Event::Upload
7373
Log::ActiveStorage::Upload.new(
74-
storage: service_name.to_s,
74+
storage: service_name.to_sym,
7575
file_id: event.payload[:key]&.to_s,
7676
checksum: event.payload[:checksum]&.to_s,
7777
duration_ms: duration_ms,
@@ -82,44 +82,44 @@ def self.process_active_storage_event(event, config)
8282
)
8383
when Event::Download
8484
Log::ActiveStorage::Download.new(
85-
storage: service_name.to_s,
85+
storage: service_name.to_sym,
8686
file_id: event.payload[:key]&.to_s,
8787
filename: event.payload[:filename],
8888
range: event.payload[:range],
8989
duration_ms: duration_ms
9090
)
9191
when Event::Delete
9292
Log::ActiveStorage::Delete.new(
93-
storage: service_name.to_s,
93+
storage: service_name.to_sym,
9494
file_id: event.payload[:key]&.to_s
9595
)
9696
when Event::Metadata
9797
Log::ActiveStorage::Metadata.new(
98-
storage: service_name.to_s,
98+
storage: service_name.to_sym,
9999
file_id: event.payload[:key]&.to_s,
100100
metadata: event.payload[:metadata]
101101
)
102102
when Event::Exist
103103
Log::ActiveStorage::Exist.new(
104-
storage: service_name.to_s,
104+
storage: service_name.to_sym,
105105
file_id: event.payload[:key]&.to_s,
106106
exist: event.payload[:exist]
107107
)
108108
when Event::Stream
109109
Log::ActiveStorage::Stream.new(
110-
storage: service_name.to_s,
110+
storage: service_name.to_sym,
111111
file_id: event.payload[:key]&.to_s,
112112
prefix: event.payload[:prefix]
113113
)
114114
when Event::Url
115115
Log::ActiveStorage::Url.new(
116-
storage: service_name.to_s,
116+
storage: service_name.to_sym,
117117
file_id: event.payload[:key]&.to_s,
118118
url: event.payload[:url]
119119
)
120120
else
121121
Log::ActiveStorage::Metadata.new(
122-
storage: service_name.to_s,
122+
storage: service_name.to_sym,
123123
file_id: event.payload[:key]&.to_s,
124124
metadata: event.payload[:metadata]
125125
)

lib/log_struct/integrations/carrierwave.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def store!(*args)
5353

5454
# Log the store operation with structured data
5555
log_data = Log::CarrierWave::Upload.new(
56-
storage: storage.class.name,
56+
storage: storage.class.name.split("::").last.downcase.to_sym,
5757
file_id: identifier,
5858
filename: file.filename,
5959
mime_type: file.content_type,
@@ -85,7 +85,7 @@ def retrieve_from_store!(identifier, *args)
8585

8686
# Log the retrieve operation with structured data
8787
log_data = Log::CarrierWave::Download.new(
88-
storage: storage.class.name,
88+
storage: storage.class.name.split("::").last.downcase.to_sym,
8989
file_id: identifier,
9090
filename: file&.filename,
9191
mime_type: file&.content_type,

lib/log_struct/integrations/shrine.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ def self.setup(config)
3737
end
3838

3939
# Create structured log data
40+
# Ensure storage is always a symbol
41+
storage_sym = payload[:storage].to_sym
42+
4043
log_data = case event_type
4144
when Event::Upload
4245
Log::Shrine::Upload.new(
43-
storage: payload[:storage],
46+
storage: storage_sym,
4447
location: payload[:location],
4548
uploader: payload[:uploader],
4649
upload_options: payload[:upload_options],
@@ -50,34 +53,34 @@ def self.setup(config)
5053
)
5154
when Event::Download
5255
Log::Shrine::Download.new(
53-
storage: payload[:storage],
56+
storage: storage_sym,
5457
location: payload[:location],
5558
download_options: payload[:download_options],
5659
additional_data: payload.except(:storage, :location, :download_options)
5760
)
5861
when Event::Delete
5962
Log::Shrine::Delete.new(
60-
storage: payload[:storage],
63+
storage: storage_sym,
6164
location: payload[:location],
6265
additional_data: payload.except(:storage, :location)
6366
)
6467
when Event::Metadata
6568
Log::Shrine::Metadata.new(
66-
storage: payload[:storage],
69+
storage: storage_sym,
6770
location: payload[:location],
6871
metadata: payload[:metadata],
6972
additional_data: payload.except(:storage, :location, :metadata)
7073
)
7174
when Event::Exist
7275
Log::Shrine::Exist.new(
73-
storage: payload[:storage],
76+
storage: storage_sym,
7477
location: payload[:location],
7578
exist: payload[:exist],
7679
additional_data: payload.except(:storage, :location, :exist)
7780
)
7881
else
7982
Log::Shrine::Metadata.new(
80-
storage: payload[:storage],
83+
storage: storage_sym,
8184
location: payload[:location],
8285
metadata: payload[:metadata]
8386
)

0 commit comments

Comments
 (0)