Class: MountableFileServer::FileAccessor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid, configuration = MountableFileServer.config) ⇒ FileAccessor

Returns a new instance of FileAccessor.



11
12
13
14
# File 'lib/mountable_file_server/file_accessor.rb', line 11

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

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



9
10
11
# File 'lib/mountable_file_server/file_accessor.rb', line 9

def configuration
  @configuration
end

#uidObject (readonly)

Returns the value of attribute uid.



9
10
11
# File 'lib/mountable_file_server/file_accessor.rb', line 9

def uid
  @uid
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/mountable_file_server/file_accessor.rb', line 28

def exist?
  pathnames.any? { |p| p.file? }
end

#pathnameObject



24
25
26
# File 'lib/mountable_file_server/file_accessor.rb', line 24

def pathname
  pathnames.find(-> { raise MissingFile }) { |p| p.file? }
end

#permanent_pathnameObject



20
21
22
# File 'lib/mountable_file_server/file_accessor.rb', line 20

def permanent_pathname
  Pathname(configuration.storage_path) + uid.type + uid
end

#temporary_pathnameObject



16
17
18
# File 'lib/mountable_file_server/file_accessor.rb', line 16

def temporary_pathname
  Pathname(configuration.storage_path) + 'tmp' + uid
end

#urlObject



32
33
34
35
36
# File 'lib/mountable_file_server/file_accessor.rb', line 32

def url
  raise NotAccessibleViaURL unless uid.public?

  URI.new (Pathname(configuration.base_url) + uid).to_s
end