Class: RepositoryManager::RepoFile
- Defined in:
- app/models/repository_manager/repo_file.rb
Instance Method Summary collapse
- #copy(options = {}) ⇒ Object
-
#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).
-
#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.
-
#download!(options = {}) ⇒ Object
Downloading this file.
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( = {}) begin copy!() 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!( = {}) new_item = RepositoryManager::RepoFile.new new_item.file = File.open(self.file.current_path) if [:source_folder] [:source_folder].add!(new_item) elsif [: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 [:owner] ? new_item.owner = [:owner] : new_item.owner = self.owner if [:sender] new_item.sender = [: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( = {}) self.download!() end |
#download!(options = {}) ⇒ Object
Downloading this file
23 24 25 |
# File 'app/models/repository_manager/repo_file.rb', line 23 def download!( = {}) file.path end |