Class: CBin::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-pahealth-bin/config/config.rb,
lib/cocoapods-pahealth-bin/config/config_asker.rb

Defined Under Namespace

Classes: Asker

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



103
104
105
106
107
108
109
110
111
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 103

def method_missing(method, *args, &block)
  if config.respond_to?(method)
    config.send(method, *args)
  elsif template_hash.keys.include?(method.to_s)
    raise Pod::Informative, "#{method} 字段必须在配置文件 #{config_file} 中设置, 请执行 init 命令配置或手动修改配置文件".red
  else
    super
  end
end

Instance Method Details

#config_fileObject



8
9
10
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 8

def config_file
  config_file_with_configuration_dependence(configuration_dependence)
end

#config_file_with_configuration_dependence(configuration_dependence) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 19

def config_file_with_configuration_dependence(configuration_dependence)
  file = config_uat_dependence_file
  if configuration_dependence == "test"
    file = config_test_dependence_file
    puts "\n======  #{configuration_dependence} 环境 ========"
  elsif configuration_dependence == "uat"
    puts "\n======  #{configuration_dependence} 环境 ========"
  else
    raise "\n=====  #{configuration_dependence} 参数有误,请检查%w[uat test]===="
  end

  File.expand_path("#{Pod::Config.instance.home_dir}/#{file}")
end

#config_test_dependence_fileObject



49
50
51
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 49

def config_test_dependence_file
  "pahealth_test.yml"
end

#config_uat_dependence_fileObject



53
54
55
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 53

def config_uat_dependence_file
  "pahealth_uat.yml"
end

#configuration_dependenceObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 33

def configuration_dependence
  #如果是dev 再去 podfile的配置文件中获取,确保是正确的, pod update时会用到
  if @configuration_dependence == "uat" || @configuration_dependence == nil
    if Pod::Config.instance.podfile
      configuration_dependence ||= Pod::Config.instance.podfile.configuration_dependence
    end
    configuration_dependence ||= "uat"
    @configuration_dependence = configuration_dependence
  end
  @configuration_dependence
end

#default_configObject



63
64
65
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 63

def default_config
  @default_config ||= Hash[template_hash.map { |k, v| [k, v[:default]] }]
end

#set_configuration_dependence(dependence) ⇒ Object



45
46
47
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 45

def set_configuration_dependence(dependence)
  @configuration_dependence = dependence
end

#sync_config(config) ⇒ Object



57
58
59
60
61
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 57

def sync_config(config)
  File.open(config_file_with_configuration_dependence(config['configuration_dependence']), 'w+') do |f|
    f.write(config.to_yaml)
  end
end

#template_hashObject



12
13
14
15
16
17
# File 'lib/cocoapods-pahealth-bin/config/config.rb', line 12

def template_hash
  {
      'configuration_dependence' => { description: '依赖环境', default: 'uat', selection: %w[uat test] },
      'code_repo_url' => { description: '私有源 Git 地址', default: 'uat环境:https://github.com/GitWangKai/ReleasePrivateRepo.git test环境:https://github.com/GitWangKai/TestPrivateRepo.git' },
  }
end