Class: Dreamcatch::Repo
- Inherits:
-
Object
- Object
- Dreamcatch::Repo
- Defined in:
- lib/dreamcatch/repo.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#webdav ⇒ Object
readonly
Returns the value of attribute webdav.
Instance Method Summary collapse
- #delete ⇒ Object
- #delete_local ⇒ Object
- #init_bare(local_repo_path) ⇒ Object
-
#initialize(opts = {}) ⇒ Repo
constructor
A new instance of Repo.
- #local_repo ⇒ Object
- #local_repo_exists? ⇒ Boolean
- #rename(new_name) ⇒ Object
- #save ⇒ Object
- #upload_to_webdav(local_dir, repo_name) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Repo
Returns a new instance of Repo.
8 9 10 11 12 13 14 15 |
# File 'lib/dreamcatch/repo.rb', line 8 def initialize(opts={}) @errors ||= [] @name = opts[:name] @dir = opts[:dir] raise Dreamcatch::Invalid.new("Repo must have name") if @name.nil? raise Dreamcatch::Invalid.new("Repo must have dir") if @dir.nil? @webdav = Dreamcatch::WebDav.new(Dreamcatch::Config.remote_url, self) end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
6 7 8 |
# File 'lib/dreamcatch/repo.rb', line 6 def errors @errors end |
#webdav ⇒ Object (readonly)
Returns the value of attribute webdav.
5 6 7 |
# File 'lib/dreamcatch/repo.rb', line 5 def webdav @webdav end |
Instance Method Details
#delete ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/dreamcatch/repo.rb', line 17 def delete if webdav.exists?("#{@name}") webdav.delete("#{@name}") else self.add_error Dreamcatch::Error.new(%Q{#{@name} does not exists}) nil end end |
#delete_local ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dreamcatch/repo.rb', line 26 def delete_local if local_repo_exists? if FileUtils.remove_dir(local_repo) == 0 true else self.add_error(Dreamcatch::Error.new(%Q{#{local_repo} could not be removed})) nil end else self.add_error Dreamcatch::Error.new(%Q{#{local_repo} does not exist locally}) nil end end |
#init_bare(local_repo_path) ⇒ Object
74 75 76 |
# File 'lib/dreamcatch/repo.rb', line 74 def (local_repo_path) Grit::Repo.(local_repo_path) end |
#local_repo ⇒ Object
62 63 64 |
# File 'lib/dreamcatch/repo.rb', line 62 def local_repo "#{@dir}/#{@name}" end |
#local_repo_exists? ⇒ Boolean
66 67 68 |
# File 'lib/dreamcatch/repo.rb', line 66 def local_repo_exists? File.exists? local_repo end |
#rename(new_name) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dreamcatch/repo.rb', line 40 def rename(new_name) if webdav.exists?("#{@name}") if !webdav.exists?("#{new_name}") webdav.rename(@name, new_name) else self.add_error Dreamcatch::Error.new(%Q{#{new_name} already exists}) nil end else self.add_error Dreamcatch::Error.new(%Q{#{@name} does not exist}) nil end end |
#save ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/dreamcatch/repo.rb', line 54 def save if local_repo_exists? upload_to_webdav(@dir, @name) elsif (local_repo) upload_to_webdav(@dir, @name) end end |
#upload_to_webdav(local_dir, repo_name) ⇒ Object
70 71 72 |
# File 'lib/dreamcatch/repo.rb', line 70 def upload_to_webdav(local_dir, repo_name) webdav.put(local_dir, repo_name) end |