Class: Pindo::IosConfigParser
- Inherits:
-
Object
- Object
- Pindo::IosConfigParser
- Includes:
- Singleton
- Defined in:
- lib/pindo/config/ios_config_parser.rb
Overview
iOS 配置解析器(单例模式)专门用于解析和处理 iOS 项目的 config.json 配置文件
使用示例:
parser = Pindo::IosConfigParser.instance
parser.load_config(config_file: 'path/to/config.json')
# 获取 Apple ID
apple_id = parser.apple_id
# 获取 Bundle ID 映射
bundle_id_map = parser.get_bundle_id_map
# 命令行参数覆盖
parser.override_apple_id('[email protected]')
parser.override_bundle_id('com.example.app')
Instance Attribute Summary collapse
-
#config_file_path ⇒ Object
readonly
Returns the value of attribute config_file_path.
-
#config_json ⇒ Object
readonly
Returns the value of attribute config_json.
Instance Method Summary collapse
-
#app_id_ios ⇒ String?
获取 App ID (Apple Store Connect).
-
#app_name ⇒ String?
获取应用名称.
-
#app_version ⇒ String?
获取应用版本.
-
#apple_id ⇒ String?
获取 Apple ID.
-
#bundle_id ⇒ String?
获取主应用 Bundle ID.
-
#bundle_id_extension ⇒ String?
获取通用 Extension Bundle ID.
-
#bundle_id_extensionad ⇒ String?
获取广告 Extension Bundle ID.
-
#bundle_id_extensionporn ⇒ String?
获取 Porn Extension Bundle ID.
-
#bundle_id_imessage ⇒ String?
获取 iMessage Extension Bundle ID.
-
#bundle_id_keyboard ⇒ String?
获取 Keyboard Extension Bundle ID.
-
#bundle_id_pushcontent ⇒ String?
获取 Push Content Extension Bundle ID.
-
#bundle_id_pushservice ⇒ String?
获取 Push Service Extension Bundle ID.
-
#bundle_id_siri ⇒ String?
获取 Siri Extension Bundle ID.
-
#bundle_id_siriui ⇒ String?
获取 Siri UI Extension Bundle ID.
-
#bundle_id_watchapp ⇒ String?
获取 Watch App Bundle ID.
-
#bundle_id_watchapp_extension ⇒ String?
获取 Watch App Extension Bundle ID.
-
#bundle_id_widget ⇒ String?
获取 Widget Extension Bundle ID.
-
#clear ⇒ Object
清除所有配置和覆盖.
-
#company_name ⇒ String?
获取公司名称.
-
#get_bundle_id_array ⇒ Array<String>
获取 Bundle ID 数组(去除 nil 值).
-
#get_bundle_id_map ⇒ Hash
获取所有 Bundle ID 的映射.
-
#group_id ⇒ String?
获取 App Group ID.
-
#icloud_id ⇒ String?
获取 iCloud Container ID.
-
#initialize ⇒ IosConfigParser
constructor
A new instance of IosConfigParser.
-
#ios_deployment_target ⇒ String?
获取 iOS 部署目标版本.
-
#load_config(config_file:) ⇒ Object
加载配置文件.
-
#loaded? ⇒ Boolean
检查配置是否已加载.
-
#override_apple_id(value) ⇒ Object
覆盖 Apple ID(命令行参数).
-
#override_bundle_id(value) ⇒ Object
覆盖主应用 Bundle ID(命令行参数).
-
#override_company_name(value) ⇒ Object
覆盖公司名称.
-
#print_config_info ⇒ Object
打印所有配置信息(用于调试).
-
#project_name ⇒ String?
获取项目名称.
-
#reload ⇒ Object
重新加载配置文件.
-
#validate_required(*required_keys) ⇒ Object
验证必需的配置项是否存在.
-
#xcode_build_type ⇒ String?
获取 Xcode 构建类型.
Constructor Details
#initialize ⇒ IosConfigParser
Returns a new instance of IosConfigParser.
26 27 28 29 30 31 |
# File 'lib/pindo/config/ios_config_parser.rb', line 26 def initialize @config_file_path = nil @config_json = nil @config_data = {} @overrides = {} end |
Instance Attribute Details
#config_file_path ⇒ Object (readonly)
Returns the value of attribute config_file_path.
24 25 26 |
# File 'lib/pindo/config/ios_config_parser.rb', line 24 def config_file_path @config_file_path end |
#config_json ⇒ Object (readonly)
Returns the value of attribute config_json.
24 25 26 |
# File 'lib/pindo/config/ios_config_parser.rb', line 24 def config_json @config_json end |
Instance Method Details
#app_id_ios ⇒ String?
获取 App ID (Apple Store Connect)
247 248 249 |
# File 'lib/pindo/config/ios_config_parser.rb', line 247 def app_id_ios @config_data[:app_id_ios] end |
#app_name ⇒ String?
获取应用名称
235 236 237 |
# File 'lib/pindo/config/ios_config_parser.rb', line 235 def app_name @config_data[:app_name] end |
#app_version ⇒ String?
获取应用版本
241 242 243 |
# File 'lib/pindo/config/ios_config_parser.rb', line 241 def app_version @config_data[:app_version] end |
#apple_id ⇒ String?
获取 Apple ID
76 77 78 |
# File 'lib/pindo/config/ios_config_parser.rb', line 76 def apple_id @overrides[:apple_id] || @config_data[:apple_id] end |
#bundle_id ⇒ String?
获取主应用 Bundle ID
102 103 104 |
# File 'lib/pindo/config/ios_config_parser.rb', line 102 def bundle_id @overrides[:bundle_id] || @config_data[:bundle_id] end |
#bundle_id_extension ⇒ String?
获取通用 Extension Bundle ID
138 139 140 |
# File 'lib/pindo/config/ios_config_parser.rb', line 138 def bundle_id_extension @config_data[:bundle_id_extension] end |
#bundle_id_extensionad ⇒ String?
获取广告 Extension Bundle ID
162 163 164 |
# File 'lib/pindo/config/ios_config_parser.rb', line 162 def bundle_id_extensionad @config_data[:bundle_id_extensionad] end |
#bundle_id_extensionporn ⇒ String?
获取 Porn Extension Bundle ID
168 169 170 |
# File 'lib/pindo/config/ios_config_parser.rb', line 168 def bundle_id_extensionporn @config_data[:bundle_id_extensionporn] end |
#bundle_id_imessage ⇒ String?
获取 iMessage Extension Bundle ID
132 133 134 |
# File 'lib/pindo/config/ios_config_parser.rb', line 132 def @config_data[:bundle_id_imessage] end |
#bundle_id_keyboard ⇒ String?
获取 Keyboard Extension Bundle ID
126 127 128 |
# File 'lib/pindo/config/ios_config_parser.rb', line 126 def bundle_id_keyboard @config_data[:bundle_id_keyboard] end |
#bundle_id_pushcontent ⇒ String?
获取 Push Content Extension Bundle ID
114 115 116 |
# File 'lib/pindo/config/ios_config_parser.rb', line 114 def bundle_id_pushcontent @config_data[:bundle_id_pushcontent] end |
#bundle_id_pushservice ⇒ String?
获取 Push Service Extension Bundle ID
120 121 122 |
# File 'lib/pindo/config/ios_config_parser.rb', line 120 def bundle_id_pushservice @config_data[:bundle_id_pushservice] end |
#bundle_id_siri ⇒ String?
获取 Siri Extension Bundle ID
144 145 146 |
# File 'lib/pindo/config/ios_config_parser.rb', line 144 def bundle_id_siri @config_data[:bundle_id_siri] end |
#bundle_id_siriui ⇒ String?
获取 Siri UI Extension Bundle ID
150 151 152 |
# File 'lib/pindo/config/ios_config_parser.rb', line 150 def bundle_id_siriui @config_data[:bundle_id_siriui] end |
#bundle_id_watchapp ⇒ String?
获取 Watch App Bundle ID
174 175 176 |
# File 'lib/pindo/config/ios_config_parser.rb', line 174 def bundle_id_watchapp @config_data[:bundle_id_watchapp] end |
#bundle_id_watchapp_extension ⇒ String?
获取 Watch App Extension Bundle ID
180 181 182 |
# File 'lib/pindo/config/ios_config_parser.rb', line 180 def bundle_id_watchapp_extension @config_data[:bundle_id_watchapp_extension] end |
#bundle_id_widget ⇒ String?
获取 Widget Extension Bundle ID
156 157 158 |
# File 'lib/pindo/config/ios_config_parser.rb', line 156 def @config_data[:bundle_id_widget] end |
#clear ⇒ Object
清除所有配置和覆盖
65 66 67 68 69 70 |
# File 'lib/pindo/config/ios_config_parser.rb', line 65 def clear @config_file_path = nil @config_json = nil @config_data = {} @overrides = {} end |
#company_name ⇒ String?
获取公司名称
88 89 90 |
# File 'lib/pindo/config/ios_config_parser.rb', line 88 def company_name @overrides[:company_name] || @config_data[:company_name] end |
#get_bundle_id_array ⇒ Array<String>
获取 Bundle ID 数组(去除 nil 值)
213 214 215 |
# File 'lib/pindo/config/ios_config_parser.rb', line 213 def get_bundle_id_array get_bundle_id_map.values end |
#get_bundle_id_map ⇒ Hash
获取所有 Bundle ID 的映射
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/pindo/config/ios_config_parser.rb', line 193 def get_bundle_id_map { "bundle_id" => bundle_id, "bundle_id_pushcontent" => bundle_id_pushcontent, "bundle_id_pushservice" => bundle_id_pushservice, "bundle_id_keyboard" => bundle_id_keyboard, "bundle_id_imessage" => , "bundle_id_extension" => bundle_id_extension, "bundle_id_siri" => bundle_id_siri, "bundle_id_siriui" => bundle_id_siriui, "bundle_id_widget" => , "bundle_id_extensionad" => bundle_id_extensionad, "bundle_id_extensionporn" => bundle_id_extensionporn, "bundle_id_watchapp" => bundle_id_watchapp, "bundle_id_watchapp_extension" => bundle_id_watchapp_extension }.compact end |
#group_id ⇒ String?
获取 App Group ID
221 222 223 |
# File 'lib/pindo/config/ios_config_parser.rb', line 221 def group_id @config_data[:group_id] end |
#icloud_id ⇒ String?
获取 iCloud Container ID
227 228 229 |
# File 'lib/pindo/config/ios_config_parser.rb', line 227 def icloud_id @config_data[:icloud_id] end |
#ios_deployment_target ⇒ String?
获取 iOS 部署目标版本
267 268 269 |
# File 'lib/pindo/config/ios_config_parser.rb', line 267 def ios_deployment_target @config_data[:ios_deployment_target] end |
#load_config(config_file:) ⇒ Object
加载配置文件
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pindo/config/ios_config_parser.rb', line 36 def load_config(config_file:) unless File.exist?(config_file) raise "配置文件不存在: #{config_file}" end @config_file_path = File.(config_file) begin @config_json = JSON.parse(File.read(@config_file_path)) rescue JSON::ParserError => e raise "配置文件格式错误: #{e.message}" end # 解析配置 parse_config_data # 检查配置版本 check_config_version self end |
#loaded? ⇒ Boolean
检查配置是否已加载
291 292 293 |
# File 'lib/pindo/config/ios_config_parser.rb', line 291 def loaded? !@config_json.nil? end |
#override_apple_id(value) ⇒ Object
覆盖 Apple ID(命令行参数)
82 83 84 |
# File 'lib/pindo/config/ios_config_parser.rb', line 82 def override_apple_id(value) @overrides[:apple_id] = value if value && !value.empty? end |
#override_bundle_id(value) ⇒ Object
覆盖主应用 Bundle ID(命令行参数)
108 109 110 |
# File 'lib/pindo/config/ios_config_parser.rb', line 108 def override_bundle_id(value) @overrides[:bundle_id] = value if value && !value.empty? end |
#override_company_name(value) ⇒ Object
覆盖公司名称
94 95 96 |
# File 'lib/pindo/config/ios_config_parser.rb', line 94 def override_company_name(value) @overrides[:company_name] = value if value && !value.empty? end |
#print_config_info ⇒ Object
打印所有配置信息(用于调试)
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/pindo/config/ios_config_parser.rb', line 298 def print_config_info puts "\n" + "=" * 80 puts "iOS 配置信息" puts "=" * 80 puts "配置文件: #{@config_file_path}" puts puts "【账号信息】" puts " Apple ID: #{apple_id}" puts " Company Name: #{company_name}" puts puts "【应用信息】" puts " App Name: #{app_name}" puts " App Version: #{app_version}" puts " App ID (iOS): #{app_id_ios}" puts puts "【Bundle ID】" puts " Main App: #{bundle_id}" get_bundle_id_map.each do |type, id| next if type == "bundle_id" puts " #{type}: #{id}" end puts puts "【App Group & iCloud】" puts " Group ID: #{group_id}" puts " iCloud ID: #{icloud_id}" puts puts "【项目信息】" puts " Project Name: #{project_name}" puts " Xcode Build Type: #{xcode_build_type}" puts " iOS Deployment Target: #{ios_deployment_target}" puts "=" * 80 puts end |
#project_name ⇒ String?
获取项目名称
255 256 257 |
# File 'lib/pindo/config/ios_config_parser.rb', line 255 def project_name @config_data[:project_name] end |
#reload ⇒ Object
重新加载配置文件
59 60 61 62 |
# File 'lib/pindo/config/ios_config_parser.rb', line 59 def reload return unless @config_file_path load_config(config_file: @config_file_path) end |
#validate_required(*required_keys) ⇒ Object
验证必需的配置项是否存在
276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/pindo/config/ios_config_parser.rb', line 276 def validate_required(*required_keys) missing_keys = [] required_keys.each do |key| value = send(key) rescue nil missing_keys << key if value.nil? || (value.respond_to?(:empty?) && value.empty?) end unless missing_keys.empty? raise "配置文件缺少必需项: #{missing_keys.join(', ')}" end end |
#xcode_build_type ⇒ String?
获取 Xcode 构建类型
261 262 263 |
# File 'lib/pindo/config/ios_config_parser.rb', line 261 def xcode_build_type @config_data[:xcode_build_type] end |