Class: Pod::Command::Mod::Source

Inherits:
Pod::Command::Mod show all
Defined in:
lib/cocoapods-modularization/command/mod/source.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Source

Returns a new instance of Source.



25
26
27
28
29
30
# File 'lib/cocoapods-modularization/command/mod/source.rb', line 25

def initialize(argv)
  @name = argv.shift_argument
  @path = argv.option('path', nil)
  @use_local = argv.flag?('local')
  super
end

Class Method Details

.optionsObject



18
19
20
21
22
23
# File 'lib/cocoapods-modularization/command/mod/source.rb', line 18

def self.options 
  [
    ['--path=URL', 'local filePath of the component'],
    ["--local", 'use local source, if local path is not specified, will clone from remote']
  ].concat(super)
end

Instance Method Details

#runObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cocoapods-modularization/command/mod/source.rb', line 56

def run
  begin
    Meta::MetaAccessor.set_source(@name)
    if @path && !@path.empty?
      UI.puts("Switch #{@name} to local path")
      Private::PrivateCache.write_path_into_cache(@name, @path)
      Meta::MetaAccessor.set_local_path(@name, @path)
    elsif @use_local
      path = Private::PrivateCache.start(@name)
      UI.puts("Switch #{@name} to local path: #{path}")
      Meta::MetaAccessor.set_local_path(@name, path)
    else
      UI.puts("Switch #{@name} to remote")
      Meta::MetaAccessor.remove_local_path(@name)
    end

    Meta::MetaReference.encode_podfile
    UI.puts("Podfile encoded")
  rescue Exception => e
    UI.puts e
  end
end

#validate!Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cocoapods-modularization/command/mod/source.rb', line 32

def validate!
  super
  help! "meta.yml not found, run `pod sync` to fix this issue" unless File.exists?(Meta::MetaConstants.meta_path)
  help! "data.yml not found, run `pod sync` to fix this issue" unless File.exists?(Meta::MetaConstants.data_path)

  help! 'A name for the Pod is required.' unless @name
  help! 'The Pod name cannot contain spaces.' if @name =~ /\s/
  help! 'The Pod name cannot contain plusses.' if @name =~ /\+/
  help! "The Pod name cannot begin with a '.'" if @name[0, 1] == '.'
  
  dependencies = Meta::MetaAccessor.dependencies()
  help! "#{@name} not found in dependencies: #{dependencies}" unless dependencies.include?(@name)

  if @path.kind_of?(String) && @path.empty?
    podspec_exists = false
    if File::exists?(@path)
      podspec_exists = true
    elsif File::exists?("#{@path}/#{@name}.podspec")
      podspec_exists = true
    end
    help! "#{@name}.podspec not found #{@path}" unless podspec_exists
  end
end