Class: Pindo::IosConfigParser

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeIosConfigParser

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_pathObject (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_jsonObject (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_iosString?

获取 App ID (Apple Store Connect)

Returns:

  • (String, nil)


247
248
249
# File 'lib/pindo/config/ios_config_parser.rb', line 247

def app_id_ios
  @config_data[:app_id_ios]
end

#app_nameString?

获取应用名称

Returns:

  • (String, nil)


235
236
237
# File 'lib/pindo/config/ios_config_parser.rb', line 235

def app_name
  @config_data[:app_name]
end

#app_versionString?

获取应用版本

Returns:

  • (String, nil)


241
242
243
# File 'lib/pindo/config/ios_config_parser.rb', line 241

def app_version
  @config_data[:app_version]
end

#apple_idString?

获取 Apple ID

Returns:

  • (String, nil)

    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_idString?

获取主应用 Bundle ID

Returns:

  • (String, nil)

    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_extensionString?

获取通用 Extension Bundle ID

Returns:

  • (String, nil)


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_extensionadString?

获取广告 Extension Bundle ID

Returns:

  • (String, nil)


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_extensionpornString?

获取 Porn Extension Bundle ID

Returns:

  • (String, nil)


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_imessageString?

获取 iMessage Extension Bundle ID

Returns:

  • (String, nil)


132
133
134
# File 'lib/pindo/config/ios_config_parser.rb', line 132

def bundle_id_imessage
  @config_data[:bundle_id_imessage]
end

#bundle_id_keyboardString?

获取 Keyboard Extension Bundle ID

Returns:

  • (String, nil)


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_pushcontentString?

获取 Push Content Extension Bundle ID

Returns:

  • (String, nil)


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_pushserviceString?

获取 Push Service Extension Bundle ID

Returns:

  • (String, nil)


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_siriString?

获取 Siri Extension Bundle ID

Returns:

  • (String, nil)


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_siriuiString?

获取 Siri UI Extension Bundle ID

Returns:

  • (String, nil)


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_watchappString?

获取 Watch App Bundle ID

Returns:

  • (String, nil)


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_extensionString?

获取 Watch App Extension Bundle ID

Returns:

  • (String, nil)


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_widgetString?

获取 Widget Extension Bundle ID

Returns:

  • (String, nil)


156
157
158
# File 'lib/pindo/config/ios_config_parser.rb', line 156

def bundle_id_widget
  @config_data[:bundle_id_widget]
end

#clearObject

清除所有配置和覆盖



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_nameString?

获取公司名称

Returns:

  • (String, nil)

    公司名称



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_arrayArray<String>

获取 Bundle ID 数组(去除 nil 值)

Returns:

  • (Array<String>)

    Bundle ID 数组



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_mapHash

获取所有 Bundle ID 的映射

Examples:

{
  "bundle_id" => "com.example.app",
  "bundle_id_pushcontent" => "com.example.app.content",
  "bundle_id_pushservice" => "com.example.app.service",
  ...
}

Returns:

  • (Hash)

    Bundle ID 映射,键为类型,值为 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_imessage,
    "bundle_id_extension" => bundle_id_extension,
    "bundle_id_siri" => bundle_id_siri,
    "bundle_id_siriui" => bundle_id_siriui,
    "bundle_id_widget" => 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_idString?

获取 App Group ID

Returns:

  • (String, nil)


221
222
223
# File 'lib/pindo/config/ios_config_parser.rb', line 221

def group_id
  @config_data[:group_id]
end

#icloud_idString?

获取 iCloud Container ID

Returns:

  • (String, nil)


227
228
229
# File 'lib/pindo/config/ios_config_parser.rb', line 227

def icloud_id
  @config_data[:icloud_id]
end

#ios_deployment_targetString?

获取 iOS 部署目标版本

Returns:

  • (String, nil)


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

加载配置文件

Parameters:

  • config_file (String)

    config.json 文件路径

Raises:



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.expand_path(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

检查配置是否已加载

Returns:

  • (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(命令行参数)

Parameters:

  • value (String)

    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(命令行参数)

Parameters:

  • value (String)

    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

覆盖公司名称

Parameters:

  • value (String)

    公司名称



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

打印所有配置信息(用于调试)



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_nameString?

获取项目名称

Returns:

  • (String, nil)


255
256
257
# File 'lib/pindo/config/ios_config_parser.rb', line 255

def project_name
  @config_data[:project_name]
end

#reloadObject

重新加载配置文件



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

验证必需的配置项是否存在

Parameters:

  • required_keys (Array<Symbol>)

    必需的配置键

Raises:



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_typeString?

获取 Xcode 构建类型

Returns:

  • (String, nil)


261
262
263
# File 'lib/pindo/config/ios_config_parser.rb', line 261

def xcode_build_type
  @config_data[:xcode_build_type]
end