class CBin::Config

Public Instance Methods

config_file() click to toggle source
# File lib/cocoapods-pahealth-bin/config/config.rb, line 7
def config_file
  File.expand_path("#{Pod::Config.instance.home_dir}/bin.yml")
end
default_config() click to toggle source
# File lib/cocoapods-pahealth-bin/config/config.rb, line 23
def default_config
  @default_config ||= Hash[template_hash.map { |k, v| [k, v[:default]] }]
end
sync_config(config) click to toggle source
# File lib/cocoapods-pahealth-bin/config/config.rb, line 17
def sync_config(config)
  File.open(config_file, 'w+') do |f|
    f.write(config.to_yaml)
  end
end
template_hash() click to toggle source
# File lib/cocoapods-pahealth-bin/config/config.rb, line 11
def template_hash
  {
      'code_repo_url' => { description: '私有源 Git 地址', default: 'git@github.com/cocoapods-spec.git' }
  }
end

Private Instance Methods

config() click to toggle source
# File lib/cocoapods-pahealth-bin/config/config.rb, line 37
def config
  @config ||= begin
                puts "====== cocoapods-pahealth-bin #{CocoapodsPahealthBin::VERSION} 版本 ======== \n"
                @config = OpenStruct.new load_config
                validate!
                @config
              end
end
load_config() click to toggle source
# File lib/cocoapods-pahealth-bin/config/config.rb, line 29
def load_config
  if File.exist?(config_file)
    YAML.load_file(config_file)
  else
    default_config
  end
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/cocoapods-pahealth-bin/config/config.rb, line 63
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
respond_to_missing?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/cocoapods-pahealth-bin/config/config.rb, line 59
def respond_to_missing?(method, include_private = false)
  config.respond_to?(method) || super
end
validate!() click to toggle source
# File lib/cocoapods-pahealth-bin/config/config.rb, line 46
def validate!
  template_hash.each do |k, v|
    selection = v[:selection]
    next if !selection || selection.empty?

    config_value = @config.send(k)
    next unless config_value
    unless selection.include?(config_value)
      raise Pod::Informative, "#{k} 字段的值必须限定在可选值 [ #{selection.join(' / ')} ] 内".red
    end
  end
end