Class: Appydave::Tools::Dam::ManifestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/appydave/tools/dam/manifest_generator.rb

Overview

Generate manifest JSON for video projects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(brand, brand_info: nil, brand_path: nil) ⇒ ManifestGenerator

Returns a new instance of ManifestGenerator.



13
14
15
16
17
# File 'lib/appydave/tools/dam/manifest_generator.rb', line 13

def initialize(brand, brand_info: nil, brand_path: nil)
  @brand_info = brand_info || load_brand_info(brand)
  @brand = @brand_info.key # Use resolved brand key, not original input
  @brand_path = brand_path || Config.brand_path(@brand)
end

Instance Attribute Details

#brandObject (readonly)

Returns the value of attribute brand.



11
12
13
# File 'lib/appydave/tools/dam/manifest_generator.rb', line 11

def brand
  @brand
end

#brand_infoObject (readonly)

Returns the value of attribute brand_info.



11
12
13
# File 'lib/appydave/tools/dam/manifest_generator.rb', line 11

def brand_info
  @brand_info
end

#brand_pathObject (readonly)

Returns the value of attribute brand_path.



11
12
13
# File 'lib/appydave/tools/dam/manifest_generator.rb', line 11

def brand_path
  @brand_path
end

Instance Method Details

#generate(output_file: nil, verbose: false) ⇒ Hash

Generate manifest for this brand

Returns:

  • (Hash)

    Result with :success, :path, and :brand keys



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/appydave/tools/dam/manifest_generator.rb', line 21

def generate(output_file: nil, verbose: false)
  output_file ||= File.join(brand_path, 'projects.json')
  ssd_backup = brand_info.locations.ssd_backup

  unless ssd_backup && !ssd_backup.empty?
    puts "⚠️  SSD backup location not configured for brand '#{brand}'"
    puts '   Manifest will only include local projects.'
  end

  ssd_available = ssd_backup && Dir.exist?(ssd_backup)

  puts "📊 Generating manifest for #{brand}..."
  puts ''

  # Collect all unique project IDs from both locations
  all_project_ids = collect_project_ids(ssd_backup, ssd_available)

  # Build project entries (empty array if no projects)
  projects = all_project_ids.empty? ? [] : build_project_entries(all_project_ids, ssd_backup, ssd_available)

  # Calculate disk usage
  disk_usage = calculate_disk_usage(projects, ssd_backup)

  # Build manifest
  manifest = {
    config: {
      brand: brand,
      local_base: brand_path,
      ssd_base: ssd_backup,
      last_updated: Time.now.utc.iso8601,
      note: 'Auto-generated manifest. Regenerate with: vat manifest'
    }.merge(disk_usage),
    projects: projects
  }

  # Write to file
  File.write(output_file, JSON.pretty_generate(manifest))

  timestamp = Time.now.strftime('%Y-%m-%d %H:%M:%S')
  puts "✅ Generated #{output_file} (#{timestamp})"
  puts "   Found #{projects.size} unique projects"
  puts ''

  # Summary stats
  show_summary(projects, disk_usage)

  # Validations
  run_validations(projects, verbose: verbose)

  # Next steps
  puts ''
  puts '💡 Next Steps:'
  puts "   dam list #{brand}              # View all projects"
  puts "   dam status #{brand}            # Check sync status"
  puts "   dam s3-up #{brand} <project>   # Upload project to S3"
  puts ''

  { success: true, brand: brand, path: output_file }
end