Class: Pod::Command::Patch::Create

Inherits:
Pod::Command::Patch show all
Defined in:
lib/cocoapods-patch/command/patch/create.rb

Instance Method Summary collapse

Methods inherited from Pod::Command::Patch

#patch_file

Constructor Details

#initialize(argv) ⇒ Create

Returns a new instance of Create.



17
18
19
20
# File 'lib/cocoapods-patch/command/patch/create.rb', line 17

def initialize(argv)
  @name = argv.shift_argument
  super
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cocoapods-patch/command/patch/create.rb', line 27

def run
  Dir.mktmpdir('cocoapods-patch-', config.project_root) do |work_dir|
    sandbox = Pod::Sandbox.new(work_dir)
    installer = Pod::Installer.new(sandbox, config.podfile)
    installer.clean_install = true

    installer.prepare
    installer.resolve_dependencies

    pod_installer = installer.send :create_pod_installer, @name
    pod_installer.install!

    theirs = Pathname.new(work_dir).join(@name).relative_path_from(config.project_root)
    ours = config.project_pods_root.join(@name).relative_path_from(config.project_root)
    gen_diff_cmd = "git diff --no-index #{theirs} #{ours} > #{patch_file}"

    did_succeed = system(gen_diff_cmd)
    if not did_succeed.nil?
      UI.puts "Created patch #{patch_file}"
    else
      UI.warn "Error creating patch for #{@name}"
    end
  end
end

#validate!Object



22
23
24
25
# File 'lib/cocoapods-patch/command/patch/create.rb', line 22

def validate!
  super
  help! 'A Pod name is required.' unless @name
end