Class: Reflection::Repository
- Inherits:
-
Object
- Object
- Reflection::Repository
- Defined in:
- lib/reflection/repository.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #clone(path) ⇒ Object
- #commit_all_new_files ⇒ Object
- #identifier ⇒ Object
-
#initialize(new_url, path = nil) ⇒ Repository
constructor
A new instance of Repository.
- #pull ⇒ Object
- #push ⇒ Object
- #reset! ⇒ Object
- #same_in_path?(path) ⇒ Boolean
Constructor Details
#initialize(new_url, path = nil) ⇒ Repository
Returns a new instance of Repository.
27 28 29 30 |
# File 'lib/reflection/repository.rb', line 27 def initialize(new_url, path = nil) self.url = new_url self.path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/reflection/repository.rb', line 8 def path @path end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/reflection/repository.rb', line 7 def url @url end |
Class Method Details
.exists?(path) ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/reflection/repository.rb', line 19 def self.exists?(path) begin Git.open(path) rescue ArgumentError return false end end |
.new_from_path(path) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/reflection/repository.rb', line 10 def self.new_from_path(path) unless self.exists?(path) raise "'#{path}' is not a valid Git repository" end repo = Git.open(path) self.new(repo.remote.url, path) end |
Instance Method Details
#clone(path) ⇒ Object
47 48 49 |
# File 'lib/reflection/repository.rb', line 47 def clone(path) Git.clone(self.url, path) end |
#commit_all_new_files ⇒ Object
51 52 53 54 55 56 |
# File 'lib/reflection/repository.rb', line 51 def commit_all_new_files repo = Git.open(self.path) Reflection.log.debug "Committing all changes.." Reflection.log.debug(repo.add) Reflection.log.debug(repo.commit_all("Updated stash.")) rescue true end |
#identifier ⇒ Object
32 33 34 |
# File 'lib/reflection/repository.rb', line 32 def identifier Digest::MD5.hexdigest(self.url) end |
#pull ⇒ Object
64 65 66 67 |
# File 'lib/reflection/repository.rb', line 64 def pull Reflection.log.debug "Pulling in #{self.path}.." Reflection.log.debug(%x((cd #{self.path} && git pull --rebase))) end |
#push ⇒ Object
58 59 60 61 62 |
# File 'lib/reflection/repository.rb', line 58 def push repo = Git.open(self.path) Reflection.log.debug "Pushing commit.." Reflection.log.debug(repo.push) end |
#reset! ⇒ Object
41 42 43 44 45 |
# File 'lib/reflection/repository.rb', line 41 def reset! Reflection.log.debug "Resetting target to HEAD" repo = Git.open(self.path) repo.reset_hard end |
#same_in_path?(path) ⇒ Boolean
36 37 38 39 |
# File 'lib/reflection/repository.rb', line 36 def same_in_path?(path) git_repo = Git.open(path) (git_repo.remote && git_repo.remote.url == self.url) || false end |