Class: PodSynchronize::Command::Synchronize

Inherits:
PodSynchronize::Command show all
Defined in:
lib/updater/synchronize.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Synchronize

Returns a new instance of Synchronize.



13
14
15
# File 'lib/updater/synchronize.rb', line 13

def initialize(argv)
  @yml_path = argv.shift_argument
end

Instance Method Details

#bootstrapObject



27
28
29
30
# File 'lib/updater/synchronize.rb', line 27

def bootstrap
  @internal_specs.git.clone(url: @config.mirror.specs_push_url)
  @master_specs.git.clone(url: @config.master_repo, options: '. --depth 1')
end

#commit_messageObject



47
48
49
50
# File 'lib/updater/synchronize.rb', line 47

def commit_message
  time_str = Time.now.strftime('%c')
  "Update #{time_str}"
end

#dependenciesObject



67
68
69
70
71
72
73
74
75
# File 'lib/updater/synchronize.rb', line 67

def dependencies
  pods_dependencies = []

  @config.podfiles.each do |podfile|
    podfile_contents = open(podfile, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}) { |io| io.read }
    pods_dependencies << YAML.load(podfile_contents)["SPEC CHECKSUMS"].keys
  end
  pods_dependencies.flatten!.uniq!
end

#runObject



77
78
79
80
81
82
83
84
# File 'lib/updater/synchronize.rb', line 77

def run
  Dir.mktmpdir do |dir|
    self.setup(temp_path: dir)
    self.bootstrap
    self.update_specs
    self.update_sources(temp_path: dir)
  end
end

#setup(temp_path:) ⇒ Object



21
22
23
24
25
# File 'lib/updater/synchronize.rb', line 21

def setup(temp_path:)
  @config = Configuration.new(path: @yml_path)
  @master_specs = Specs.new(path: File.join(temp_path, 'master'), whitelist: dependencies, specs_root: 'Specs')
  @internal_specs = Specs.new(path: File.join(temp_path, 'local'))
end

#update_sources(temp_path:) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/updater/synchronize.rb', line 52

def update_sources(temp_path:)
  @master_specs.pods.each do |pod|
    pod.git.path = File.join(temp_path, 'source_cache', pod.name)
    pod.git.clone(url: pod.git_source, options: ". --bare")
    pod.git.create_github_repo(
      access_token: @config.mirror.github.access_token,
      org: @config.mirror.github.organisation,
      name: pod.name,
      endpoint: @config.mirror.github.endpoint
    )
    pod.git.set_origin(url: "#{@config.mirror.source_push_url}/#{pod.name}.git")
    pod.git.push(remote: nil, options: '--mirror')
  end
end

#update_specsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/updater/synchronize.rb', line 32

def update_specs
  @internal_specs.merge_pods(@master_specs.pods)

  @internal_specs.pods.each do |pod|
    pod.versions.each do |version|
      if version.contents["source"]["git"]
        version.contents["source"]["git"] = "#{@config.mirror.source_clone_url}/#{pod.name}.git"
      end
    end
    pod.save
  end
  @internal_specs.git.commit(message: commit_message)
  @internal_specs.git.push
end

#validate!Object

Raises:



17
18
19
# File 'lib/updater/synchronize.rb', line 17

def validate!
  raise Informative, "Please specify a valid CONFIG path" unless @yml_path
end