Class: Appydave::Tools::Dam::Config

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

Overview

VatConfig - Configuration management for Video Asset Tools

Manages VIDEO_PROJECTS_ROOT and brand path resolution

Class Method Summary collapse

Class Method Details

.available_brandsArray<String>

Get list of available brands Reads from brands.json if available, falls back to filesystem scan



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/appydave/tools/dam/config.rb', line 103

def available_brands
  Appydave::Tools::Configuration::Config.configure
  brands_config = Appydave::Tools::Configuration::Config.brands

  # If brands are configured in brands.json, use those
  configured_brands = brands_config.brands
  return configured_brands.map(&:shortcut).sort unless configured_brands.empty?

  # Fall back to filesystem scan
  root = projects_root
  return [] unless Dir.exist?(root)

  Dir.glob("#{root}/v-*")
     .select { |path| File.directory?(path) }
     .reject { |path| File.basename(path) == 'v-shared' } # Exclude infrastructure
     .select { |path| valid_brand?(path) }
     .map { |path| File.basename(path) }
     .map { |brand| brand.sub(/^v-/, '') }
     .sort
end

.available_brands_displayObject

Get available brands with both shortcut and name for error messages



125
126
127
128
129
130
131
132
# File 'lib/appydave/tools/dam/config.rb', line 125

def available_brands_display
  Appydave::Tools::Configuration::Config.configure
  brands_config = Appydave::Tools::Configuration::Config.brands

  brands_config.brands.map do |brand|
    "  #{brand.shortcut.ljust(10)} - #{brand.name}"
  end.sort.join("\n")
end

.brand_path(brand_key) ⇒ String

Get the full path to a brand directory



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/appydave/tools/dam/config.rb', line 27

def brand_path(brand_key)
  Appydave::Tools::Configuration::Config.configure
  brand_info = Appydave::Tools::Configuration::Config.brands.get_brand(brand_key)

  # If brand has configured video_projects path, use it
  return brand_info.locations.video_projects if brand_info.locations.video_projects && !brand_info.locations.video_projects.empty? && Dir.exist?(brand_info.locations.video_projects)

  # Fall back to projects_root + expanded brand name
  brand = expand_brand(brand_key)
  path = File.join(projects_root, brand)

  unless Dir.exist?(path)
    brands_list = available_brands_display
    # Use fuzzy matching to suggest similar brands (check both shortcuts and keys)
    Appydave::Tools::Configuration::Config.configure
    brands_config = Appydave::Tools::Configuration::Config.brands
    all_brand_identifiers = brands_config.brands.flat_map { |b| [b.shortcut, b.key] }.uniq
    suggestions = FuzzyMatcher.find_matches(brand_key, all_brand_identifiers, threshold: 3)
    raise BrandNotFoundError.new(path, brands_list, suggestions)
  end

  path
end

.configured?Boolean

Validate that VIDEO_PROJECTS_ROOT is configured



150
151
152
153
154
# File 'lib/appydave/tools/dam/config.rb', line 150

def configured?
  Appydave::Tools::Configuration::Config.configure
  root = Appydave::Tools::Configuration::Config.settings.video_projects_root
  !root.nil? && !root.empty? && Dir.exist?(root)
end

.expand_brand(shortcut) ⇒ String

Expand brand shortcut to full brand name Delegates to BrandResolver for centralized brand resolution



96
97
98
# File 'lib/appydave/tools/dam/config.rb', line 96

def expand_brand(shortcut)
  BrandResolver.expand(shortcut)
end

.git_remote(brand_key) ⇒ String?

Get git remote URL for a brand (with self-healing)



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/appydave/tools/dam/config.rb', line 70

def git_remote(brand_key)
  Appydave::Tools::Configuration::Config.configure
  brands_config = Appydave::Tools::Configuration::Config.brands
  brand_info = brands_config.get_brand(brand_key)

  # 1. Check if git_remote is already configured
  return brand_info.git_remote if brand_info.git_remote && !brand_info.git_remote.empty?

  # 2. Try to infer from git command
  brand_path_dir = brand_path(brand_key)
  inferred_remote = infer_git_remote(brand_path_dir)

  # 3. Auto-save if inferred successfully
  if inferred_remote
    brand_info.git_remote = inferred_remote
    brands_config.set_brand(brand_info.key, brand_info)
    brands_config.save
  end

  inferred_remote
end

.project_path(brand_key, project_id) ⇒ String

Get the full path to a project directory, respecting brand’s projects_subfolder setting



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/appydave/tools/dam/config.rb', line 55

def project_path(brand_key, project_id)
  Appydave::Tools::Configuration::Config.configure
  brand_info = Appydave::Tools::Configuration::Config.brands.get_brand(brand_key)
  brand_dir = brand_path(brand_key)

  if brand_info.settings.projects_subfolder && !brand_info.settings.projects_subfolder.empty?
    File.join(brand_dir, brand_info.settings.projects_subfolder, project_id)
  else
    File.join(brand_dir, project_id)
  end
end

.projects_rootString

Get the root directory for all video projects



13
14
15
16
17
18
19
20
21
22
# File 'lib/appydave/tools/dam/config.rb', line 13

def projects_root
  # Use settings.json configuration
  Appydave::Tools::Configuration::Config.configure
  root = Appydave::Tools::Configuration::Config.settings.video_projects_root

  return root if root && !root.empty? && Dir.exist?(root)

  # Fall back to auto-detection if not configured
  detect_projects_root
end

.valid_brand?(brand_path) ⇒ Boolean

Check if directory is a valid brand



137
138
139
140
141
142
143
144
145
146
# File 'lib/appydave/tools/dam/config.rb', line 137

def valid_brand?(brand_path)
  # A valid brand is a v-* directory that contains project subdirectories
  # (This allows brands in development without .video-tools.env yet)

  # Must have at least one subdirectory that looks like a project
  Dir.glob("#{brand_path}/*")
     .select { |path| File.directory?(path) }
     .reject { |path| File.basename(path).start_with?('.', '_') }
     .any?
end