Class: Pod::Command::Repo::PushCodingAr
- Inherits:
-
Pod::Command::Repo
- Object
- Pod::Command
- Pod::Command::Repo
- Pod::Command::Repo::PushCodingAr
- Extended by:
- Executable
- Defined in:
- lib/coding_ar_command.rb
Instance Method Summary collapse
- #coding_ar_repo_url ⇒ Object
- #create_pod_tar_gz ⇒ Object
- #create_spec_json ⇒ Object
- #file_push_profile(path) ⇒ Object
-
#initialize(argv) ⇒ PushCodingAr
constructor
A new instance of PushCodingAr.
- #post_pod_with_spec(pod_path, spec_path) ⇒ Object
- #run ⇒ Object
- #spec ⇒ Object
- #tmp_dir ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(argv) ⇒ PushCodingAr
Returns a new instance of PushCodingAr.
71 72 73 74 75 |
# File 'lib/coding_ar_command.rb', line 71 def initialize(argv) @repo = argv.shift_argument @podspec = argv.shift_argument super end |
Instance Method Details
#coding_ar_repo_url ⇒ Object
170 171 172 |
# File 'lib/coding_ar_command.rb', line 170 def coding_ar_repo_url File.read File.join(Config.instance.repos_dir, @repo, ".coding_ar_url") end |
#create_pod_tar_gz ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/coding_ar_command.rb', line 103 def create_pod_tar_gz require 'digest/sha1' require 'find' pod_dir = File.join(tmp_dir, "pod") FileUtils.mkdir_p(pod_dir) pod_root = File.dirname Pathname(@podspec).realpath path_list = Pod::Sandbox::PathList.new(pod_root) file_accessors ||= spec.available_platforms.flat_map do |platform| Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform)) end pod_files = Pod::Sandbox::FileAccessor.all_files(file_accessors).map do |path| Find.find(path).select { |path| File.file? path} end pod_files.flatten.each do |source| target = File.join(pod_dir, Pathname(source).relative_path_from(pod_root)) FileUtils.mkdir_p(File.dirname(target)) FileUtils.copy_file(source, target) end tar_gz_path = File.join(tmp_dir, "#{spec.name}-#{spec.version}.tar.gz") Dir.chdir(pod_dir) { tar!('-czf', tar_gz_path, '.') } tar_gz_path end |
#create_spec_json ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/coding_ar_command.rb', line 134 def create_spec_json require 'json' FileUtils.mkdir_p(tmp_dir) podspec_json_path = File.join(tmp_dir, "#{spec.name}.podspec.json") podspec_json = File.new(podspec_json_path, "wb") podspec_json.puts(spec.to_pretty_json) podspec_json.close podspec_json_path end |
#file_push_profile(path) ⇒ Object
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/coding_ar_command.rb', line 174 def file_push_profile(path) require 'digest/sha1' content = File.read(path) { 'size' => File.lstat(path).size, 'base64_content' => Base64.strict_encode64(content), 'sha1_digest' => Digest::SHA1.hexdigest(content) } end |
#post_pod_with_spec(pod_path, spec_path) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/coding_ar_command.rb', line 145 def post_pod_with_spec(pod_path, spec_path) require 'json' request_body = { 'pod' => file_push_profile(pod_path), 'spec' => file_push_profile(spec_path) } request_body_json_path = File.join(tmp_dir, "request_body.json") request_body_json = File.new(request_body_json_path, "wb") request_body_json.puts(request_body.to_json) request_body_json.close require 'coding_ar_util' CodingArUtil.push_pod(coding_ar_repo_url, request_body_json_path) end |
#run ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/coding_ar_command.rb', line 84 def run unless File.file? File.join(Config.instance.repos_dir, @repo, ".coding_ar_url") raise Informative, "`#@repo` is not a CODING-AR repo.".red end FileUtils.mkdir_p tmp_dir begin UI.section("Pushing pod `#{spec.name} #{spec.version.to_s}`` to CODING-AR repo `#@repo`") do pod_tar_gz_path = create_pod_tar_gz podspec_json_path = create_spec_json post_pod_with_spec(pod_tar_gz_path, podspec_json_path) end UI.puts "Successfully push pod `#{spec.name} #{spec.version.to_s}`` to CODING-AR repo `#@repo`".green ensure FileUtils.rm_rf tmp_dir end end |
#spec ⇒ Object
161 162 163 164 |
# File 'lib/coding_ar_command.rb', line 161 def spec spec_file = Pathname(@podspec) spec = Pod::Specification.from_file(spec_file) end |
#tmp_dir ⇒ Object
166 167 168 |
# File 'lib/coding_ar_command.rb', line 166 def tmp_dir File.join(Config.instance.repos_dir, @repo, '.tmp', spec.name, spec.version.to_s) end |
#validate! ⇒ Object
77 78 79 80 81 82 |
# File 'lib/coding_ar_command.rb', line 77 def validate! super unless @repo && @podspec help! 'This command requires both a repo and a podspec.' end end |