Class: Notebook::StorageAdapters::Filesystem

Inherits:
Base
  • Object
show all
Defined in:
lib/notebook/storage_adapters/filesystem.rb

Instance Method Summary collapse

Methods inherited from Base

#get

Constructor Details

#initialize(attachment, options = {}) ⇒ Filesystem

Returns a new instance of Filesystem.



6
7
8
9
# File 'lib/notebook/storage_adapters/filesystem.rb', line 6

def initialize(attachment, options = {})
  super
  @storage_directory = options.fetch('storage_directory', Notebook.public_directory)
end

Instance Method Details

#deleteObject



11
12
13
# File 'lib/notebook/storage_adapters/filesystem.rb', line 11

def delete
  !!FileUtils.remove(url)
end

#uploadObject



15
16
17
18
# File 'lib/notebook/storage_adapters/filesystem.rb', line 15

def upload
  # When this command is successful, it returns nil
  FileUtils.copy(attachment.file, @storage_directory).nil?
end

#urlObject



20
21
22
# File 'lib/notebook/storage_adapters/filesystem.rb', line 20

def url
  (@storage_directory + File.basename(attachment.file)).to_s
end