Rename a method

This commit is contained in:
Eugene Burmakin 2025-08-22 20:40:06 +02:00
parent 96c9f1030c
commit 7eb3103645
5 changed files with 7 additions and 13 deletions

View file

@ -114,7 +114,7 @@ class ImportsController < ApplicationController
def detect_import_source(file_attachment)
temp_file_path = Imports::SecureFileDownloader.new(file_attachment).download_to_temp_file
Imports::SourceDetector.new_from_file(temp_file_path).detect_source
Imports::SourceDetector.new_from_file_header(temp_file_path).detect_source
rescue StandardError => e
Rails.logger.warn "Failed to auto-detect import source for #{file_attachment.filename}: #{e.message}"
nil

View file

@ -70,7 +70,6 @@ class GoogleMaps::SemanticHistoryImporter
end.compact
end
def parse_timeline_object(timeline_object)
if timeline_object['activitySegment'].present?
parse_activity_segment(timeline_object['activitySegment'])

View file

@ -14,13 +14,9 @@ class Imports::Create
import.update!(status: :processing)
broadcast_status_update
# Download file to temp location for processing
temp_file_path = Imports::SecureFileDownloader.new(import.file).download_to_temp_file
# Auto-detect source if not already set
source = import.source.presence || detect_source_from_file(temp_file_path)
# Create importer with file path for efficient processing
importer(source).new(import, user.id, temp_file_path).call
schedule_stats_creating(user.id)
@ -34,7 +30,6 @@ class Imports::Create
create_import_failed_notification(import, user, e)
ensure
# Cleanup temp file
if temp_file_path && File.exist?(temp_file_path)
File.unlink(temp_file_path)
end
@ -94,7 +89,7 @@ class Imports::Create
end
def detect_source_from_file(temp_file_path)
detector = Imports::SourceDetector.new_from_file(temp_file_path)
detector = Imports::SourceDetector.new_from_file_header(temp_file_path)
detector.detect_source!
end

View file

@ -60,7 +60,7 @@ class Imports::SourceDetector
@file_path = file_path
end
def self.new_from_file(file_path)
def self.new_from_file_header(file_path)
filename = File.basename(file_path)
# For detection, read only first 2KB to optimize performance

View file

@ -120,17 +120,17 @@ RSpec.describe Imports::SourceDetector do
end
end
describe '.new_from_file' do
describe '.new_from_file_header' do
context 'with Google Records file' do
let(:fixture_path) { file_fixture('google/records.json').to_s }
it 'detects source correctly from file path' do
detector = described_class.new_from_file(fixture_path)
detector = described_class.new_from_file_header(fixture_path)
expect(detector.detect_source).to eq(:google_records)
end
it 'can detect source efficiently from file' do
detector = described_class.new_from_file(fixture_path)
detector = described_class.new_from_file_header(fixture_path)
# Verify it can detect correctly using file-based approach
expect(detector.detect_source).to eq(:google_records)
@ -141,7 +141,7 @@ RSpec.describe Imports::SourceDetector do
let(:fixture_path) { file_fixture('geojson/export.json').to_s }
it 'detects source correctly from file path' do
detector = described_class.new_from_file(fixture_path)
detector = described_class.new_from_file_header(fixture_path)
expect(detector.detect_source).to eq(:geojson)
end
end