Class: Sunshine::Repo
- Inherits:
-
Object
- Object
- Sunshine::Repo
- Defined in:
- lib/sunshine/repo.rb
Overview
An abstract class to wrap simple basic scm features. The primary function of repo objects is to get information about the scm branch that is being deployed and to check it out on remote deploy servers:
svn = SvnRepo.new "svn://path/to/repo", :flags => "--ignore-externals"
The :flags option can be a String or an Array and supports any scm checkout (or clone for git) options.
Instance Attribute Summary collapse
-
#scm ⇒ Object
readonly
Returns the value of attribute scm.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.detect(path = ".", shell = nil) ⇒ Object
Looks for .git and .svn directories and determines if the passed path is a recognized repo.
-
.get_info(path = ".", shell = nil) ⇒ Object
Gets repo information for the specified dir - Implemented by subclass.
-
.new_of_type(repo_type, url, options = {}) ⇒ Object
Creates a new repo subclass object: Repo.new_of_type :svn, “path/to/repo/tags/releasetag” Repo.new_of_type :git, “[email protected]:repo/path”.
Instance Method Summary collapse
-
#checkout_to(path, shell = nil) ⇒ Object
Checkout code to a shell and return an info log hash: repo.chekout_to server, “some/path” #=> => 123, :committer => ‘someone’, :date => time_obj ….
-
#do_checkout(path, shell) ⇒ Object
Checkout the repo - implemented by subclass.
-
#get_repo_info(path = ".", shell = nil) ⇒ Object
Returns the repo information as a hash.
-
#initialize(url, options = {}) ⇒ Repo
constructor
A new instance of Repo.
-
#name ⇒ Object
Get the name of the specified repo - implemented by subclass.
-
#scm_flags ⇒ Object
Returns the set scm flags as a string.
Constructor Details
#initialize(url, options = {}) ⇒ Repo
Returns a new instance of Repo.
62 63 64 65 66 67 |
# File 'lib/sunshine/repo.rb', line 62 def initialize url, ={} @scm = self.class.name.split("::").last.sub('Repo', '').downcase @url = url @flags = [*[:flags]].compact end |
Instance Attribute Details
#scm ⇒ Object (readonly)
Returns the value of attribute scm.
60 61 62 |
# File 'lib/sunshine/repo.rb', line 60 def scm @scm end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
60 61 62 |
# File 'lib/sunshine/repo.rb', line 60 def url @url end |
Class Method Details
.detect(path = ".", shell = nil) ⇒ Object
Looks for .git and .svn directories and determines if the passed path is a recognized repo. Does not check for RsyncRepo since it’s a special case. Returns the appropriate repo object:
Repo.detect "path/to/svn/repo/dir"
#=> <SvnRepo @url="svn://url/of/checked/out/repo">
Repo.detect "path/to/git/repo/dir"
#=> <GitRepo, @url="git://url/of/git/repo", @branch="master">
Repo.detect "invalid/repo/path"
#=> nil
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sunshine/repo.rb', line 38 def self.detect path=".", shell=nil if SvnRepo.valid? path info = SvnRepo.get_info path, shell SvnRepo.new info[:url], info elsif GitRepo.valid? path info = GitRepo.get_info path, shell GitRepo.new info[:url], info end end |
.get_info(path = ".", shell = nil) ⇒ Object
Gets repo information for the specified dir - Implemented by subclass
54 55 56 57 |
# File 'lib/sunshine/repo.rb', line 54 def self.get_info path=".", shell=nil raise RepoError, "The 'get_info' method must be implemented by child classes" end |
.new_of_type(repo_type, url, options = {}) ⇒ Object
Creates a new repo subclass object:
Repo.new_of_type :svn, "https://path/to/repo/tags/releasetag"
Repo.new_of_type :git, "[email protected]:repo/path"
21 22 23 24 |
# File 'lib/sunshine/repo.rb', line 21 def self.new_of_type repo_type, url, ={} repo = "#{repo_type.to_s.capitalize}Repo" Sunshine.const_get(repo).new(url, ) end |
Instance Method Details
#checkout_to(path, shell = nil) ⇒ Object
Checkout code to a shell and return an info log hash:
repo.chekout_to server, "some/path"
#=> {:revision => 123, :committer => 'someone', :date => time_obj ...}
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sunshine/repo.rb', line 75 def checkout_to path, shell=nil shell ||= Sunshine.shell Sunshine.logger.info @scm, "Checking out to #{shell.host} #{path}" do shell.call "test -d #{path} && rm -rf #{path} || echo false" shell.call "mkdir -p #{path}" do_checkout path, shell get_repo_info path, shell end end |
#do_checkout(path, shell) ⇒ Object
Checkout the repo - implemented by subclass
93 94 95 96 |
# File 'lib/sunshine/repo.rb', line 93 def do_checkout path, shell raise RepoError, "The 'do_checkout' method must be implemented by child classes" end |
#get_repo_info(path = ".", shell = nil) ⇒ Object
Returns the repo information as a hash.
119 120 121 122 123 |
# File 'lib/sunshine/repo.rb', line 119 def get_repo_info path=".", shell=nil defaults = {:type => @scm, :url => @url, :path => path} defaults.merge self.class.get_info(path, shell) end |
#name ⇒ Object
Get the name of the specified repo - implemented by subclass
102 103 104 105 |
# File 'lib/sunshine/repo.rb', line 102 def name raise RepoError, "The 'name' method must be implemented by child classes" end |
#scm_flags ⇒ Object
Returns the set scm flags as a string
111 112 113 |
# File 'lib/sunshine/repo.rb', line 111 def scm_flags @flags.join(" ") end |