Module: Appydave::Tools::Dam::LocalSyncStatus

Defined in:
lib/appydave/tools/dam/local_sync_status.rb

Overview

Enriches S3 scan project data with local s3-staging sync status

Class Method Summary collapse

Class Method Details

.enrich!(matched_projects, brand_key) ⇒ Object

Mutates matched_projects hash to add :local_status and :local_file_count keys

Parameters:

  • matched_projects (Hash)

    Map of project_id => S3 data hash

  • brand_key (String)

    Brand key (e.g., ‘appydave’)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/appydave/tools/dam/local_sync_status.rb', line 13

def enrich!(matched_projects, brand_key)
  matched_projects.each do |project_id, data|
    project_path = Appydave::Tools::Dam::Config.project_path(brand_key, project_id)
    s3_staging_path = File.join(project_path, 's3-staging')

    if !Dir.exist?(project_path)
      data[:local_status] = :no_project # Project directory doesn't exist
    elsif !Dir.exist?(s3_staging_path)
      data[:local_status] = :no_files # Project exists but no downloads yet
    else
      # Count local files in s3-staging
      local_files = Dir.glob(File.join(s3_staging_path, '**', '*'))
                       .select { |f| File.file?(f) }
                       .reject { |f| File.basename(f).include?('Zone.Identifier') } # Exclude Windows metadata

      s3_file_count = data[:file_count]
      local_file_count = local_files.size

      data[:local_status] = if local_file_count.zero?
                              :no_files
                            elsif local_file_count == s3_file_count
                              :synced # Fully synced
                            else
                              :partial # Some files downloaded
                            end

      data[:local_file_count] = local_file_count
    end
  end
end

.format(status, local_count, s3_count) ⇒ String

Format local sync status symbol for display

Parameters:

  • status (Symbol)

    :synced, :no_files, :partial, :no_project

  • local_count (Integer, nil)

    Number of local files

  • s3_count (Integer)

    Number of S3 files

Returns:

  • (String)

    Formatted status string



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/appydave/tools/dam/local_sync_status.rb', line 49

def format(status, local_count, s3_count)
  case status
  when :synced
    '✓ Synced'
  when :no_files
    '⚠ None'
  when :partial
    "#{local_count}/#{s3_count}"
  when :no_project
    '✗ Missing'
  else
    'Unknown'
  end
end