Class: Appydave::Tools::Configuration::Models::BrandsConfig
- Inherits:
-
ConfigBase
- Object
- ConfigBase
- Appydave::Tools::Configuration::Models::BrandsConfig
- Defined in:
- lib/appydave/tools/configuration/models/brands_config.rb
Overview
Brands configuration for video project management
Defined Under Namespace
Classes: BrandAws, BrandInfo, BrandLocation, BrandSettings, UserInfo
Instance Attribute Summary
Attributes inherited from ConfigBase
Instance Method Summary collapse
-
#brands ⇒ Object
Retrieve a list of all brands.
-
#get_brand(brand_key) ⇒ Object
Retrieve brand information by brand key (string or symbol).
-
#get_brands_for_user(user_key) ⇒ Object
Get brands for a specific user.
-
#get_user(user_key) ⇒ Object
Get user information.
- #key?(key) ⇒ Boolean
- #print ⇒ Object
-
#set_brand(brand_key, brand_info) ⇒ Object
Set brand information.
-
#set_user(user_key, user_info) ⇒ Object
Set user information.
- #shortcut?(shortcut) ⇒ Boolean
-
#users ⇒ Object
Retrieve a list of all users.
Methods inherited from ConfigBase
#config_name, #debug, #initialize, #load, #name, #save
Constructor Details
This class inherits a constructor from Appydave::Tools::Configuration::Models::ConfigBase
Instance Method Details
#brands ⇒ Object
Retrieve a list of all brands
57 58 59 60 61 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 57 def brands data['brands'].map do |key, info| BrandInfo.new(key, info) end end |
#get_brand(brand_key) ⇒ Object
Retrieve brand information by brand key (string or symbol)
10 11 12 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 43 44 45 46 47 48 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 10 def get_brand(brand_key) brand_key_str = brand_key.to_s log.info "Looking up brand: '#{brand_key_str}'" if debug_mode? # Validate data structure unless data.is_a?(Hash) log.error "Config data is not a Hash: #{data.class}" raise "Invalid brands config: data is #{data.class}, expected Hash" end unless data['brands'].is_a?(Hash) log.error "Config data['brands'] is #{data['brands'].class}, expected Hash" log.error "Available keys in data: #{data.keys.inspect}" raise "Invalid brands config: 'brands' key is #{data['brands'].class}, expected Hash" end log.info "Available brands: #{data['brands'].keys.inspect}" if debug_mode? # Try direct key lookup first (case-insensitive) brand_entry = data['brands'].find { |key, _info| key.downcase == brand_key_str.downcase } if brand_entry actual_key = brand_entry[0] log.info "Found brand by key: '#{actual_key}'" if debug_mode? return BrandInfo.new(actual_key, brand_entry[1]) end # Try lookup by shortcut (case-insensitive) brand_entry = data['brands'].find { |_key, info| info['shortcut']&.downcase == brand_key_str.downcase } if brand_entry actual_key = brand_entry[0] log.info "Found brand by shortcut: '#{actual_key}'" if debug_mode? return BrandInfo.new(actual_key, brand_entry[1]) end # Return default if not found (use normalized lowercase key) log.warn "Brand not found: '#{brand_key_str}', returning default" if debug_mode? BrandInfo.new(brand_key_str.downcase, default_brand_info) end |
#get_brands_for_user(user_key) ⇒ Object
Get brands for a specific user
64 65 66 67 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 64 def get_brands_for_user(user_key) user_key = user_key.to_s brands.select { |brand| brand.team.include?(user_key) } end |
#get_user(user_key) ⇒ Object
Get user information
70 71 72 73 74 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 70 def get_user(user_key) user_key = user_key.to_s info = data['users'][user_key] || default_user_info UserInfo.new(user_key, info) end |
#key?(key) ⇒ Boolean
89 90 91 92 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 89 def key?(key) key = key.to_s data['brands'].key?(key) end |
#print ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 99 def print log.heading 'Brands Configuration' print_brands = brands.map do |brand| { key: brand.key, name: brand.name, shortcut: brand.shortcut, type: brand.type, youtube_channels: brand.youtube_channels.join(', '), team: brand.team.join(', '), video_projects: print_location(brand.locations.video_projects), ssd_backup: print_location(brand.locations.ssd_backup), aws_profile: brand.aws.profile } end tp print_brands, :key, :name, :shortcut, :type, :youtube_channels, :team, :video_projects, :ssd_backup, :aws_profile end |
#set_brand(brand_key, brand_info) ⇒ Object
Set brand information
51 52 53 54 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 51 def set_brand(brand_key, brand_info) data['brands'] ||= {} data['brands'][brand_key.to_s] = brand_info.to_h end |
#set_user(user_key, user_info) ⇒ Object
Set user information
77 78 79 80 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 77 def set_user(user_key, user_info) data['users'] ||= {} data['users'][user_key.to_s] = user_info.to_h end |
#shortcut?(shortcut) ⇒ Boolean
94 95 96 97 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 94 def shortcut?(shortcut) shortcut = shortcut.to_s data['brands'].values.any? { |info| info['shortcut'] == shortcut } end |
#users ⇒ Object
Retrieve a list of all users
83 84 85 86 87 |
# File 'lib/appydave/tools/configuration/models/brands_config.rb', line 83 def users data['users'].map do |key, info| UserInfo.new(key, info) end end |