Class: DYAutomate::Command::CodeSnippet

Inherits:
DYAutomate::Command show all
Defined in:
lib/DYAutomate/Command/codeSnippet.rb

Instance Attribute Summary collapse

Attributes inherited from DYAutomate::Command

#config, #env_str, #repo_name

Instance Method Summary collapse

Methods inherited from DYAutomate::Command

#pp

Constructor Details

#initialize(argv) ⇒ CodeSnippet

Returns a new instance of CodeSnippet.



19
20
21
22
# File 'lib/DYAutomate/Command/codeSnippet.rb', line 19

def initialize(argv)
  super
  @xcode_snippsets_path = File.join(Dir.home,"/Library/Developer/Xcode/UserData/CodeSnippets")
end

Instance Attribute Details

#xcode_snippsets_pathObject

当前路径



17
18
19
# File 'lib/DYAutomate/Command/codeSnippet.rb', line 17

def xcode_snippsets_path
  @xcode_snippsets_path
end

Instance Method Details

#clone_templatesObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/DYAutomate/Command/codeSnippet.rb', line 41

def clone_templates
  tempPath = File.join(Dir.home,'Documents','.iOSCodeSnippet')
  unless Dir.exist?(tempPath)
    system("mkdir #{tempPath}")
  end
  system ("git clone #{@config.codeSnippsets_git_url} --depth 1 #{tempPath}")
  Dir.chdir("#{tempPath}/CodeSnippets")
  Dir.glob("*") do |path|
    FileUtils.cp(path, @xcode_snippsets_path)
  end
  `rm -rf #{tempPath}`
  puts "安装完成..."
end

#runObject



37
38
39
# File 'lib/DYAutomate/Command/codeSnippet.rb', line 37

def run
  clone_templates
end

#validate!Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/DYAutomate/Command/codeSnippet.rb', line 24

def validate!
  super
  unless Dir.exist?(@xcode_snippsets_path)
    help! "
      error -- >!!! Not found Xcode CodeSnippets at the #{@xcode_snippsets_path}"
  end

  unless @config.detailObj.codeSnippsets_git_url
    help! "
      error -- >!!! Not found the value of codeSnippsets_git_url"
  end
end