Class: RepoTools::Puller
- Inherits:
-
Object
- Object
- RepoTools::Puller
- Defined in:
- lib/repo_tools/puller.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
-
#ssh_clone_url ⇒ Object
readonly
Returns the value of attribute ssh_clone_url.
Instance Method Summary collapse
- #clean_and_clone ⇒ Object
- #clone ⇒ Object
- #destination_dirname ⇒ Object
- #git_status_checker ⇒ Object
-
#initialize(ssh_clone_url, project_root, environment) ⇒ Puller
constructor
A new instance of Puller.
- #log ⇒ Object
- #log_clone ⇒ Object
- #project_name ⇒ Object
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
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
3 4 5 |
# File 'lib/repo_tools/puller.rb', line 3 def environment @environment end |
#project_root ⇒ Object (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_url ⇒ Object (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_clone ⇒ Object
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 |
#clone ⇒ Object
22 23 24 |
# File 'lib/repo_tools/puller.rb', line 22 def clone `git clone #{ssh_clone_url} #{destination_dirname}` end |
#destination_dirname ⇒ Object
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_checker ⇒ Object
18 19 20 |
# File 'lib/repo_tools/puller.rb', line 18 def git_status_checker GitStatusChecker.new(destination_dirname) end |
#log ⇒ Object
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_clone ⇒ Object
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_name ⇒ Object
38 39 40 |
# File 'lib/repo_tools/puller.rb', line 38 def project_name ssh_clone_url.match(/\/((\w|\-)+)/)[1] end |