Class: Pod::CacheProxySource::CacheProxySourceHelper
- Inherits:
-
Object
- Object
- Pod::CacheProxySource::CacheProxySourceHelper
- Defined in:
- lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb
Class Method Summary collapse
- .check_auth_conf_exists(host) ⇒ TrueClass, FalseClass
- .check_source_conf_exists(source_name) ⇒ Void
- .get_all_auths ⇒ Array<Pod::CacheProxyAuth>
- .get_all_sources ⇒ Array<Pod::CacheProxySource>
- .get_auth_conf_file_name ⇒ String
- .get_auth_conf_path(host) ⇒ String
- .get_auth_root_dir ⇒ String
- .get_cache_proxy_auth_conf_host(host) ⇒ Pod::CacheProxyAuth
- .get_cache_proxy_auth_conf_path(path) ⇒ Pod::CacheProxyAuth
- .get_cache_proxy_root_dir ⇒ String
- .get_cache_proxy_source_conf(cache_source_name) ⇒ Pod::CacheProxySource
-
.get_source_conf_file_name ⇒ Object
@@return [String].
- .get_source_conf_path(source_name) ⇒ String
- .get_source_root_dir(source_name) ⇒ String
- .init_cache_proxy_auth(host, token) ⇒ Void
- .init_cache_proxy_source(cache_source_name, cache_source_url, user, password) ⇒ Void
- .load_auth_conf_host(host) ⇒ Hash
- .load_auth_conf_path(path) ⇒ Hash
- .load_source_conf(source_name) ⇒ Hash
- .remove_cache_proxy_auth(host) ⇒ Void
- .remove_cache_proxy_source(cache_source_name) ⇒ Void
- .save_cache_proxy_auth_conf(host, token) ⇒ Void
- .save_cache_proxy_source_conf(source_name, url, user, password) ⇒ Void
Class Method Details
.check_auth_conf_exists(host) ⇒ TrueClass, FalseClass
48 49 50 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 48 def self.check_auth_conf_exists(host) File.exist?(get_auth_conf_path(host)) end |
.check_source_conf_exists(source_name) ⇒ Void
86 87 88 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 86 def self.check_source_conf_exists(source_name) File.exist?(get_source_conf_path(source_name)) end |
.get_all_auths ⇒ Array<Pod::CacheProxyAuth>
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 166 def self.get_all_auths return [] unless Dir.exist?(get_auth_root_dir) list = [] Find.find(get_auth_root_dir) do |path| next unless File.file?(path) && path.end_with?(get_auth_conf_file_name) next unless (conf = get_cache_proxy_auth_conf_path(path)) next if conf.host.blank? || conf.token.blank? list << conf end list end |
.get_all_sources ⇒ Array<Pod::CacheProxySource>
247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 247 def self.get_all_sources return [] unless Dir.exist?(get_cache_proxy_root_dir) list = [] Find.find(get_cache_proxy_root_dir) do |path| next unless File.file?(path) && path.end_with?(get_source_conf_file_name) pn = Pathname.new(path) source_name = pn.dirname.basename next unless (conf = get_cache_proxy_source_conf(source_name)) list << conf end list end |
.get_auth_conf_file_name ⇒ String
34 35 36 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 34 def self.get_auth_conf_file_name ".auth_conf.yml" end |
.get_auth_conf_path(host) ⇒ String
41 42 43 44 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 41 def self.get_auth_conf_path(host) uri = URI.parse(host) "#{get_auth_root_dir}/#{uri.host}/#{get_auth_conf_file_name}" end |
.get_auth_root_dir ⇒ String
28 29 30 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 28 def self.get_auth_root_dir "#{Pod::Config.instance.home_dir}/cache-proxy-auth" end |
.get_cache_proxy_auth_conf_host(host) ⇒ Pod::CacheProxyAuth
153 154 155 156 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 153 def self.get_cache_proxy_auth_conf_host(host) return nil unless (cnf = load_auth_conf_host(host)) Pod::CacheProxyAuth.new(cnf['host'], cnf['token']) end |
.get_cache_proxy_auth_conf_path(path) ⇒ Pod::CacheProxyAuth
160 161 162 163 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 160 def self.get_cache_proxy_auth_conf_path(path) return nil unless (cnf = load_auth_conf_path(path)) Pod::CacheProxyAuth.new(cnf['host'], cnf['token']) end |
.get_cache_proxy_root_dir ⇒ String
16 17 18 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 16 def self.get_cache_proxy_root_dir "#{Pod::Config.instance.home_dir}/cache-proxy" end |
.get_cache_proxy_source_conf(cache_source_name) ⇒ Pod::CacheProxySource
241 242 243 244 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 241 def self.get_cache_proxy_source_conf(cache_source_name) return nil unless (cnf = load_source_conf(cache_source_name)) Pod::CacheProxySource.new(cnf['name'], cnf['url'], cnf['user'], cnf['password']) end |
.get_source_conf_file_name ⇒ Object
@@return [String]
74 75 76 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 74 def self.get_source_conf_file_name ".cache_proxy_conf.yml" end |
.get_source_conf_path(source_name) ⇒ String
80 81 82 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 80 def self.get_source_conf_path(source_name) "#{get_source_root_dir(source_name)}/#{get_source_conf_file_name}" end |
.get_source_root_dir(source_name) ⇒ String
22 23 24 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 22 def self.get_source_root_dir(source_name) "#{Pod::Config.instance.home_dir}/cache-proxy/#{source_name}" end |
.init_cache_proxy_auth(host, token) ⇒ Void
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 119 def self.init_cache_proxy_auth(host, token) begin show_output = Pod::Config.instance.verbose? pn = Pathname(get_auth_conf_path(host)) FileUtils.mkdir_p(pn.parent) unless Dir.exist?(pn.parent) Pod::UI. "Generating auth conf .....".yellow if show_output save_cache_proxy_auth_conf(host, token) Pod::UI. "Successfully added auth #{host} ".green if show_output rescue Exception => e Pod::UI. "发生异常,清理文件 .....".yellow if show_output pn = Pathname(get_auth_conf_path(host)) FileUtils.rm_rf(pn.parent) if Dir.exist?(pn.parent) Pod::UI. e..yellow if show_output Pod::UI. e.backtrace.inspect.yellow if show_output raise e end end |
.init_cache_proxy_source(cache_source_name, cache_source_url, user, password) ⇒ Void
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 205 def self.init_cache_proxy_source(cache_source_name, cache_source_url, user, password) begin show_output = Pod::Config.instance.verbose? cache_source_root_path = "#{get_source_root_dir(cache_source_name)}" FileUtils.rm_rf(cache_source_root_path) if Dir.exist?(cache_source_root_path) FileUtils.mkdir_p(cache_source_root_path) Pod::UI. "Generating source conf .....".yellow if show_output save_cache_proxy_source_conf(cache_source_name, cache_source_url, user, password) Pod::UI. "Successfully added repo #{cache_source_name}".green if show_output rescue Exception => e Pod::UI. "发生异常,清理文件 .....".yellow if show_output FileUtils.rm_rf(cache_source_root_path) if Dir.exist?(cache_source_root_path) Pod::UI. e..yellow if show_output Pod::UI. e.backtrace.inspect.yellow if show_output raise e end end |
.load_auth_conf_host(host) ⇒ Hash
54 55 56 57 58 59 60 61 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 54 def self.load_auth_conf_host(host) path = get_auth_conf_path(host) if File.exist?(path) YAML.load_file(path) else nil end end |
.load_auth_conf_path(path) ⇒ Hash
65 66 67 68 69 70 71 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 65 def self.load_auth_conf_path(path) if File.exist?(path) YAML.load_file(path) else nil end end |
.load_source_conf(source_name) ⇒ Hash
92 93 94 95 96 97 98 99 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 92 def self.load_source_conf(source_name) path = get_source_conf_path(source_name) if File.exist?(path) YAML.load_file(path) else nil end end |
.remove_cache_proxy_auth(host) ⇒ Void
143 144 145 146 147 148 149 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 143 def self.remove_cache_proxy_auth(host) show_output = Pod::Config.instance.verbose? path = Pathname(get_auth_conf_path(host)) FileUtils.rm_rf(path.parent) if Dir.exist?(path.parent) Pod::UI. "Successfully remove auth #{host}".green if show_output end |
.remove_cache_proxy_source(cache_source_name) ⇒ Void
230 231 232 233 234 235 236 237 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 230 def self.remove_cache_proxy_source(cache_source_name) show_output = Pod::Config.instance.verbose? cache_source_root_path = "#{get_source_root_dir(cache_source_name)}" FileUtils.rm_rf(cache_source_root_path) if Dir.exist?(cache_source_root_path) Pod::UI. "Successfully remove repo #{cache_source_name}".green if show_output end |
.save_cache_proxy_auth_conf(host, token) ⇒ Void
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 104 def self.save_cache_proxy_auth_conf(host, token) path = get_auth_conf_path(host) auth = { 'host' => host, 'token' => token, } conf = File.new(path, "wb") conf << auth.to_yaml conf.close end |
.save_cache_proxy_source_conf(source_name, url, user, password) ⇒ Void
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb', line 183 def self.save_cache_proxy_source_conf(source_name, url, user, password) path = get_source_conf_path(source_name) info = { 'name' => source_name, 'url' => url, } info['user'] = user unless user.blank? info['password'] = password unless password.blank? conf = File.new(path, "wb") conf << info.to_yaml conf.close end |