Class: Pod::Command::Repo::PushCodingAr

Inherits:
Pod::Command::Repo show all
Extended by:
Executable
Defined in:
lib/coding_ar_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ PushCodingAr

Returns a new instance of PushCodingAr.



72
73
74
75
76
# File 'lib/coding_ar_command.rb', line 72

def initialize(argv)
  @repo = argv.shift_argument
  @podspec = argv.shift_argument
  super
end

Instance Method Details

#coding_ar_repo_urlObject



181
182
183
# File 'lib/coding_ar_command.rb', line 181

def coding_ar_repo_url
  File.read File.join(Config.instance.repos_dir, @repo, ".coding_ar_url")
end

#create_pod_tar_gzObject



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
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/coding_ar_command.rb', line 104

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 = []

  # Add main spec
  file_accessors += spec.available_platforms.flat_map do |platform|
    Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform))
  end

  # Add subspecs
  spec.subspecs.each do |subspec|
    file_accessors += subspec.available_platforms.flat_map do |platform|
      Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform))
    end
  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_jsonObject



145
146
147
148
149
150
151
152
153
154
# File 'lib/coding_ar_command.rb', line 145

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



185
186
187
188
189
190
191
192
193
194
# File 'lib/coding_ar_command.rb', line 185

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



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/coding_ar_command.rb', line 156

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

#runObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/coding_ar_command.rb', line 85

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

#specObject



172
173
174
175
# File 'lib/coding_ar_command.rb', line 172

def spec
  spec_file = Pathname(@podspec)
  spec = Pod::Specification.from_file(spec_file)
end

#tmp_dirObject



177
178
179
# File 'lib/coding_ar_command.rb', line 177

def tmp_dir
  File.join(Config.instance.repos_dir, @repo, '.tmp', spec.name, spec.version.to_s)
end

#validate!Object



78
79
80
81
82
83
# File 'lib/coding_ar_command.rb', line 78

def validate!
  super
  unless @repo && @podspec
    help! 'This command requires both a repo and a podspec.'
  end
end