Class: Artifact::Repo
- Inherits:
-
Object
- Object
- Artifact::Repo
- Defined in:
- lib/artifact.rb
Defined Under Namespace
Classes: SyncError
Instance Method Summary collapse
- #exists?(path) ⇒ Boolean
-
#initialize(full_path) ⇒ Repo
constructor
A new instance of Repo.
- #move(from, to, author) ⇒ Object
- #remove(path, author) ⇒ Object
- #save(path, author, check = true) ⇒ Object
- #sync! ⇒ Object
Constructor Details
#initialize(full_path) ⇒ Repo
Returns a new instance of Repo.
151 152 153 154 |
# File 'lib/artifact.rb', line 151 def initialize(full_path) @root = full_path @git = Rugged::Repository.new(full_path) end |
Instance Method Details
#exists?(path) ⇒ Boolean
187 188 189 |
# File 'lib/artifact.rb', line 187 def exists?(path) !!file_status(path) rescue false end |
#move(from, to, author) ⇒ Object
171 172 173 174 175 176 177 178 179 |
# File 'lib/artifact.rb', line 171 def move(from, to, ) Artifact.ensure_dir!(Artifact.full_path(to)) FileUtils.mv(Artifact.full_path(from), Artifact.full_path(to)) @git.index.remove(from) @git.index.add(to) @git.index.write write_commit("Moved #{from} --> #{to}", ) end |
#remove(path, author) ⇒ Object
181 182 183 184 185 |
# File 'lib/artifact.rb', line 181 def remove(path, ) @git.index.remove(path) @git.index.write write_commit("Removed #{path}", ) end |
#save(path, author, check = true) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/artifact.rb', line 156 def save(path, , check = true) # index.add expects a clean path, without any leading ./ # so make sure we're passing a clean pathname path = path.sub(/^\.\//, '') if check && !new_file?(path) && !modified?(path) raise "No changes in file: #{path}" end # puts "Adding to index: #{path}" @git.index.add(path) @git.index.write write_commit("Saved #{path}", ) end |