class CBin::Config_Hot_Key

Public Instance Methods

config_file() click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 9
def config_file
  config_file_with_hot_key_index(hot_key_index)
end
config_file_whith_hot_key_index(hot_key_index) click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 36
def config_file_whith_hot_key_index(hot_key_index)
  "hot_key_#{hot_key_index}.yml"
end
config_file_with_hot_key_index(hot_key_index) click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 21
def config_file_with_hot_key_index(hot_key_index)
  file = config_file_whith_hot_key_index(hot_key_index)
  raise "\n=====  #{hot_key_index} 参数有误,请检查%w[1 2 3...]===" unless (hot_key_index.to_i).is_a?(Integer)
  File.expand_path("#{Pod::Config.instance.home_dir}/#{file}")
end
default_config() click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 46
def default_config
  @default_config ||= Hash[template_hash.map { |k, v| [k, v[:default]] }]
end
hot_key_index() click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 27
def hot_key_index
  @hot_key_index = 1 if @hot_key_index.is_a?(NilClass)
  @hot_key_index
end
set_hot_key_index(hot_key_index) click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 32
def set_hot_key_index(hot_key_index)
  @hot_key_index = hot_key_index
end
sync_config(config) click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 40
def sync_config(config)
  File.open(config_file_with_hot_key_index(config['hot_key_index']), 'w+') do |f|
    f.write(config.to_yaml)
  end
end
template_hash() click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 13
def template_hash
  {
      'hot_key_index' => { description: '快捷键', default: '1', selection: %w[1 2 3...] },
      'hot_key_dir'   => { description: '快捷键执行目录', default: '' },
      'hot_key_cmd'   => { description: '快捷键执行命令', default: 'pod bin update --no-repo-update' }
  }
end

Private Instance Methods

config() click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 61
def config
  @config ||= begin
                puts "====== cocoapods-tdf-bin #{CBin::VERSION} 版本 ======== \n"
                @config = OpenStruct.new load_config
                validate!
                @config
              end
end
load_config() click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 52
def load_config
  file = config_file
  if (!file.nil?) && 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-tdf-bin/config/config_hot_key.rb, line 87
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-tdf-bin/config/config_hot_key.rb, line 83
def respond_to_missing?(method, include_private = false)
  config.respond_to?(method) || super
end
validate!() click to toggle source
# File lib/cocoapods-tdf-bin/config/config_hot_key.rb, line 70
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