Class: CBin::Config

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

Defined Under Namespace

Classes: Asker, Builder

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



113
114
115
116
117
118
119
120
121
# File 'lib/cocoapods-tj/config/config.rb', line 113

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

#binary_upload_urlObject



47
48
49
50
# File 'lib/cocoapods-tj/config/config.rb', line 47

def binary_upload_url
  cut_string = "/%s/%s/zip"
  binary_download_url[0,binary_download_url.length - cut_string.length]
end

#config_debug_iphoneos_fileObject



56
57
58
# File 'lib/cocoapods-tj/config/config.rb', line 56

def config_debug_iphoneos_file
  "bin_debug_iphoneos.yml"
end

#config_dev_fileObject



64
65
66
# File 'lib/cocoapods-tj/config/config.rb', line 64

def config_dev_file
  "bin.yml"
end

#config_fileObject



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

def config_file
  config_file_with_configuration_env(configuration_env)
end

#config_file_with_configuration_env(configuration_env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cocoapods-tj/config/config.rb', line 23

def config_file_with_configuration_env(configuration_env)
  file = config_dev_file
  if configuration_env == "release_iphoneos"
    file = config_release_iphoneos_file
  elsif configuration_env == "debug_iphoneos"
    file = config_debug_iphoneos_file
  elsif configuration_env == "dev"
  else
    raise "\n=====  #{configuration_env} 参数有误,请检查%w[dev debug_iphoneos release_iphoneos]===="
  end
  File.expand_path("#{Pod::Config.instance.installation_root}/#{file}")
end

#config_release_iphoneos_fileObject



60
61
62
# File 'lib/cocoapods-tj/config/config.rb', line 60

def config_release_iphoneos_file
  "bin_release_iphoneos.yml"
end

#configuration_envObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/cocoapods-tj/config/config.rb', line 36

def configuration_env
  if @configuration_env == "dev" || @configuration_env == nil
    if Pod::Config.instance.podfile
      configuration_env ||= Pod::Config.instance.podfile.configuration_env
    end
    configuration_env ||= "dev"
    @configuration_env = configuration_env
  end
  @configuration_env
end

#default_configObject



74
75
76
# File 'lib/cocoapods-tj/config/config.rb', line 74

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

#set_configuration_env(env) ⇒ Object



52
53
54
# File 'lib/cocoapods-tj/config/config.rb', line 52

def set_configuration_env(env)
  @configuration_env = env
end

#sync_config(config) ⇒ Object



68
69
70
71
72
# File 'lib/cocoapods-tj/config/config.rb', line 68

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

#template_hashObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/cocoapods-tj/config/config.rb', line 12

def template_hash
  {
      'configuration_env' => { description: '编译环境', default: 'dev', selection: %w[dev debug_iphoneos release_iphoneos] },
      'code_repo_url' => { description: '源码私有源 Git 地址', default: '[email protected]:songpanfei/spf_code_specs.git' },
      'binary_repo_url' => { description: '二进制私有源 Git 地址', default: '[email protected]:songpanfei/spf_bin_specs.git' },
      'binary_download_url' => { description: '二进制下载地址,内部会依次传入组件名称与版本,替换字符串中的 %s ', default: 'http://localhost:8080/frameworks/%s/%s/zip' },
      # 'binary_type' => { description: '二进制打包类型', default: 'framework', selection: %w[framework library] },
      'download_file_type' => { description: '下载二进制文件类型', default: 'zip', selection: %w[zip tgz tar tbz txz dmg] }
  }
end