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.



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

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

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



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

def configuration
  @configuration
end

#uidObject (readonly)

Returns the value of attribute uid.



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

def uid
  @uid
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


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

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

#pathnameObject



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

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

#permanent_pathnameObject



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

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

#temporary_pathnameObject



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

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

#urlObject



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

def url
  raise NotAccessibleViaURL unless uid.public?

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