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.



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_urlObject



162
163
164
# File 'lib/coding_ar_command.rb', line 162

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

#create_pod_tar_gzObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/coding_ar_command.rb', line 100

def create_pod_tar_gz
  require 'digest/sha1'
  
  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::Sandbox::FileAccessor.all_files(file_accessors).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



126
127
128
129
130
131
132
133
134
135
# File 'lib/coding_ar_command.rb', line 126

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



166
167
168
169
170
171
172
173
174
175
# File 'lib/coding_ar_command.rb', line 166

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



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/coding_ar_command.rb', line 137

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
# File 'lib/coding_ar_command.rb', line 85

def run
  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



153
154
155
156
# File 'lib/coding_ar_command.rb', line 153

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

#tmp_dirObject



158
159
160
# File 'lib/coding_ar_command.rb', line 158

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
83
# File 'lib/coding_ar_command.rb', line 77

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