Class: MountableFileServer::FileAccessor
- Inherits:
-
Object
- Object
- MountableFileServer::FileAccessor
- Defined in:
- lib/mountable_file_server/file_accessor.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#initialize(uid, configuration = MountableFileServer.config) ⇒ FileAccessor
constructor
A new instance of FileAccessor.
- #pathname ⇒ Object
- #permanent_pathname ⇒ Object
- #temporary_pathname ⇒ Object
- #url ⇒ Object
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
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
9 10 11 |
# File 'lib/mountable_file_server/file_accessor.rb', line 9 def configuration @configuration end |
#uid ⇒ Object (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
28 29 30 |
# File 'lib/mountable_file_server/file_accessor.rb', line 28 def exist? pathnames.any? { |p| p.file? } end |
#pathname ⇒ Object
24 25 26 |
# File 'lib/mountable_file_server/file_accessor.rb', line 24 def pathname pathnames.find(-> { raise MissingFile }) { |p| p.file? } end |
#permanent_pathname ⇒ Object
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_pathname ⇒ Object
16 17 18 |
# File 'lib/mountable_file_server/file_accessor.rb', line 16 def temporary_pathname Pathname(configuration.storage_path) + 'tmp' + uid end |
#url ⇒ Object
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 |