Class: RepositoryManager::RepoFile

Inherits:
RepoItem
  • Object
show all
Defined in:
app/models/repository_manager/repo_file.rb

Instance Method Summary collapse

Methods inherited from RepoItem

#can_be_shared_without_nesting?, #is_file?, #is_folder?, #move, #move!, #name_exist_in_siblings?, #rename, #rename!

Instance Method Details

#copy(options = {}) ⇒ Object



56
57
58
59
60
61
62
# File 'app/models/repository_manager/repo_file.rb', line 56

def copy(options = {})
  begin
    copy!(options)
  rescue RepositoryManager::ItemExistException, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
    false
  end
end

#copy!(options = {}) ⇒ Object

Copy itself into the source_folder options

:source_folder = the folder in witch you copy this item
:owner = the owner of the item
:sender = the sender of the item (if you don't specify sender.. The sender is still the same)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/repository_manager/repo_file.rb', line 32

def copy!(options = {})
  new_item = RepositoryManager::RepoFile.new
  new_item.file = File.open(self.file.current_path)

  if options[:source_folder]
    options[:source_folder].add!(new_item)
  elsif options[:owner].repo_item_name_exist_in_root?(new_item.name)
    self.errors.add(:copy, I18n.t('repository_manager.errors.repo_item.item_exist'))
    raise RepositoryManager::ItemExistException.new("copy failed. The repo_file '#{new_item.name}' already exist in root.")
  end

  options[:owner] ? new_item.owner = options[:owner] : new_item.owner = self.owner
  if options[:sender]
    new_item.sender = options[:sender]
    #elsif options[:owner]
    #  new_item.sender = options[:owner]
  else
    new_item.sender = self.sender
  end

  new_item.save!
  new_item
end

#download(options = {}) ⇒ Object

Return the name of the file with his extension def name

if self.name.blank?
  file.url.split('/').last
else
  self.name
end

end



18
19
20
# File 'app/models/repository_manager/repo_file.rb', line 18

def download(options = {})
  self.download!(options)
end

#download!(options = {}) ⇒ Object

Downloading this file



23
24
25
# File 'app/models/repository_manager/repo_file.rb', line 23

def download!(options = {})
  file.path
end