Class: HBHConfig::Config
- Inherits:
-
Object
- Object
- HBHConfig::Config
- Defined in:
- lib/cocoapods-hbh/config/config.rb,
lib/cocoapods-hbh/config/config_asker.rb
Defined Under Namespace
Classes: Asker
Instance Method Summary collapse
- #config ⇒ Object
- #config_file ⇒ Object
- #config_file_with_configuration ⇒ Object
- #config_name ⇒ Object
- #default_config ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_config ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #sync_config(config) ⇒ Object
- #template_hash ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
69 70 71 |
# File 'lib/cocoapods-hbh/config/config.rb', line 69 def initialize end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cocoapods-hbh/config/config.rb', line 73 def method_missing(method, *args, &block) if config.respond_to?(method) config.send(method, *args) elsif template_hash.keys.include?(method.to_s) if method.to_s == "is_git_hooks" else raise Pod::Informative, "#{method} 字段必须在配置文件 #{config_name} 中设置, 请手动修改配置文件".red end else super end end |
Instance Method Details
#config ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/cocoapods-hbh/config/config.rb', line 87 def config @config ||= begin puts "====== cocoapods-hbh #{CocoapodsHbh::VERSION} 版本 ======== \n" @config = OpenStruct.new load_config @config end end |
#config_file ⇒ Object
33 34 35 |
# File 'lib/cocoapods-hbh/config/config.rb', line 33 def config_file config_file_with_configuration() end |
#config_file_with_configuration ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/cocoapods-hbh/config/config.rb', line 42 def config_file_with_configuration() file = config_name file_path = "#{Pod::Config.instance.installation_root}/#{file}" if file_path.blank? file_path = "#{Pod::Config.instance.home_dir}/#{file}" end File.(file_path) end |
#config_name ⇒ Object
37 38 39 |
# File 'lib/cocoapods-hbh/config/config.rb', line 37 def config_name "HBHConfig.yml" end |
#default_config ⇒ Object
65 66 67 |
# File 'lib/cocoapods-hbh/config/config.rb', line 65 def default_config @default_config ||= Hash[template_hash.map { |k, v| [k, v[:default]] }] end |
#load_config ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cocoapods-hbh/config/config.rb', line 52 def load_config if File.exist?(config_name) YAML.load_file(config_name) else aFile = File.new(config_name, "w+") if aFile aFile.syswrite(template_hash.to_yaml) end YAML.load_file(config_name) # raise "请在你的根目录配置创建并配置HBHConfig.yml文件" end end |
#sync_config(config) ⇒ Object
26 27 28 29 30 |
# File 'lib/cocoapods-hbh/config/config.rb', line 26 def sync_config(config) File.open(config_file_with_configuration(), 'w+') do |f| f.write(config.to_yaml) end end |
#template_hash ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cocoapods-hbh/config/config.rb', line 8 def template_hash { 'hbh_specs_env' => { 'description' => '私有仓库环境配置', 'specs_name' => '私有仓库名称', 'specs_url' => '私有仓库地址', }, 'submodule_env' => { 'description' => '子仓库环境配置', 'sub_path' => '子模块存储路径' , 'sub_url' => '子模块厂库地址' , }, 'is_turn_swiftint' => false, 'is_turn_tinypng' => true, 'cocoapods_version' => '1.10.1', } end |