Class: MountableFileServer::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/mountable_file_server/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration = MountableFileServer.config) ⇒ Storage

Returns a new instance of Storage.



5
6
7
# File 'lib/mountable_file_server/storage.rb', line 5

def initialize(configuration = MountableFileServer.config)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



3
4
5
# File 'lib/mountable_file_server/storage.rb', line 3

def configuration
  @configuration
end

Instance Method Details

#move_to_permanent_storage(uid) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/mountable_file_server/storage.rb', line 21

def move_to_permanent_storage(uid)
  source = FileAccessor.new(uid, configuration).temporary_pathname
  destination = FileAccessor.new(uid, configuration).permanent_pathname
  destination.dirname.mkpath

  source.rename destination
end

#remove_from_storage(uid) ⇒ Object



29
30
31
32
# File 'lib/mountable_file_server/storage.rb', line 29

def remove_from_storage(uid)
  source = FileAccessor.new(uid, configuration).pathname
  source.delete
end

#store_permanent(uid, input) ⇒ Object



15
16
17
18
19
# File 'lib/mountable_file_server/storage.rb', line 15

def store_permanent(uid, input)
  destination = FileAccessor.new(uid, configuration).permanent_pathname
  destination.dirname.mkpath
  IO.copy_stream input, destination
end

#store_temporary(uid, input) ⇒ Object



9
10
11
12
13
# File 'lib/mountable_file_server/storage.rb', line 9

def store_temporary(uid, input)
  destination = FileAccessor.new(uid, configuration).temporary_pathname
  destination.dirname.mkpath
  IO.copy_stream input, destination
end