Class: Pod::Command::Privacy::Config

Inherits:
Pod::Command::Privacy show all
Defined in:
lib/cocoapods-privacy/command/privacy/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Config

Returns a new instance of Config.



13
14
15
16
# File 'lib/cocoapods-privacy/command/privacy/config.rb', line 13

def initialize(argv)
    @config = argv.shift_argument
    super
end

Instance Method Details

#copy_local_configObject



51
52
53
54
55
56
57
58
59
# File 'lib/cocoapods-privacy/command/privacy/config.rb', line 51

def copy_local_config
  # 配置文件目录
  cache_config_file = PrivacyUtils.cache_config_file

  # 复制本地文件
  FileUtils.cp(@config, cache_config_file)

  puts "配置文件已复制到: #{cache_config_file}"
end

#download_remote_configObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cocoapods-privacy/command/privacy/config.rb', line 37

def download_remote_config
  # 配置文件目录
  cache_config_file = PrivacyUtils.cache_config_file

  # 开始下载
  system("curl -o #{cache_config_file} #{@config}")

  if File.exist?(cache_config_file)
    puts "配置文件已下载到: #{cache_config_file}"
  else
    raise Informative, "配置文件下载出错,请检查下载地址#{@config}"
  end
end

#load_config_fileObject



28
29
30
31
32
33
34
35
# File 'lib/cocoapods-privacy/command/privacy/config.rb', line 28

def load_config_file
  # 检查 @config 是远程 URL 还是本地文件路径
  if @config.start_with?('http')
    download_remote_config
  else
    copy_local_config
  end
end

#runObject



24
25
26
# File 'lib/cocoapods-privacy/command/privacy/config.rb', line 24

def run
  load_config_file()
end

#validate!Object

Raises:

  • (Informative)


18
19
20
21
22
# File 'lib/cocoapods-privacy/command/privacy/config.rb', line 18

def validate!
    super
    help! 'A config url is required.' unless @config
    raise Informative, "配置文件格式不是 JSON,请检查配置#{@config}" unless @config.end_with?(".json")                
end