Class: RepoTools::Puller

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ssh_clone_url, project_root, environment) ⇒ Puller

Returns a new instance of Puller.



5
6
7
8
9
# File 'lib/repo_tools/puller.rb', line 5

def initialize(ssh_clone_url, project_root, environment)
  @ssh_clone_url = ssh_clone_url
  @project_root = project_root
  @environment = environment
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



3
4
5
# File 'lib/repo_tools/puller.rb', line 3

def environment
  @environment
end

#project_rootObject (readonly)

Returns the value of attribute project_root.



3
4
5
# File 'lib/repo_tools/puller.rb', line 3

def project_root
  @project_root
end

#ssh_clone_urlObject (readonly)

Returns the value of attribute ssh_clone_url.



3
4
5
# File 'lib/repo_tools/puller.rb', line 3

def ssh_clone_url
  @ssh_clone_url
end

Instance Method Details

#clean_and_cloneObject



11
12
13
14
15
16
# File 'lib/repo_tools/puller.rb', line 11

def clean_and_clone
  return if git_status_checker.up_to_date?
  FileUtils.rm_rf destination_dirname
  clone
  log_clone
end

#cloneObject



22
23
24
# File 'lib/repo_tools/puller.rb', line 22

def clone
  `git clone #{ssh_clone_url} #{destination_dirname}`
end

#destination_dirnameObject



32
33
34
35
36
# File 'lib/repo_tools/puller.rb', line 32

def destination_dirname
  p = Pathname.new(project_root).join('tmp', environment, project_name)
  FileUtils.mkdir_p(p.dirname)
  p
end

#git_status_checkerObject



18
19
20
# File 'lib/repo_tools/puller.rb', line 18

def git_status_checker
  GitStatusChecker.new(destination_dirname)
end

#logObject



42
43
44
45
46
47
# File 'lib/repo_tools/puller.rb', line 42

def log
  p = Pathname.new(project_root).join('log', environment).join("#{project_name}.log")
  FileUtils.mkdir_p(p.dirname)
  FileUtils.touch(p)
  p
end

#log_cloneObject



26
27
28
29
30
# File 'lib/repo_tools/puller.rb', line 26

def log_clone
  File.open(log, 'a') do |f|
    f.puts "[#{Time.now.utc.iso8601}]: #{project_name} was cloned"
  end
end

#project_nameObject



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

def project_name
  ssh_clone_url.match(/\/((\w|\-)+)/)[1]
end