Class: GitCloner::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/git_cloner_core.rb

Overview

GitCloner Core

Constant Summary collapse

GIT_CLONER_FILE =
'Gitclonerfile'
GIT_CLONER_TEMPLATE =
<<-EOS
# encoding: utf-8

# default_output place
# default_output is required
# default_output allow only String
# default_output's default value => "./"
default_output "./"

# git repositries
# repo allow only Array(in Array, Hash[:place, :output, :copies])
# copies is option.
# copies must have Array[Hash{:from, :to}].
# you can copy files or directories.
# repo's default value => []
repos [
  {
place: 'https://github.com/tbpgr/rspec_piccolo.git',
output: './tmp',
copies: [
  {from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
  {from: "./tmp/rspec_piccolo/spec", to: "./sample"}
]
  }
]
EOS

Instance Method Summary collapse

Instance Method Details

#executeObject

clone git repositories



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/git_cloner_core.rb', line 43

def execute
  dsl = get_dsl
  base = Dir.pwd
  default_output = dsl.git_cloner.default_output
  tmp_repos = dsl.git_cloner.repos
  fail ArgumentError, 'invalid repos. repos must be Array.' unless tmp_repos.is_a? Array
  tmp_repos.each do |repo|
    fail ArgumentError, 'invalid repos. repos-Array must have Hash' unless repo.is_a? Hash
    fail ArgumentError, 'invalid key. Hash must contain :place key' unless repo.key? :place
    repo_name = get_repo_name repo[:place]
    target = get_output(repo[:output], default_output)
    FileUtils.mkdir_p(target) unless Dir.exists? target
    Dir.chdir(target)
    result = system("git clone #{repo[:place]} --depth=1")
    remove_dot_git_directory repo_name
    show_result_message(result, repo_name)
    Dir.chdir base
    next if repo[:copies].nil?
    copy_targets repo[:copies]
  end
end

#initObject

generate Gitclonerfile to current directory.



38
39
40
# File 'lib/git_cloner_core.rb', line 38

def init
  File.open(GIT_CLONER_FILE, 'w') { |f|f.puts GIT_CLONER_TEMPLATE }
end