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.
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
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
8 9 10 |
# File 'lib/mountable_file_server/file_accessor.rb', line 8 def configuration @configuration end |
#uid ⇒ Object (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
27 28 29 |
# File 'lib/mountable_file_server/file_accessor.rb', line 27 def exist? pathnames.any? { |p| p.file? } end |
#pathname ⇒ Object
23 24 25 |
# File 'lib/mountable_file_server/file_accessor.rb', line 23 def pathname pathnames.find(-> { raise MissingFile }) { |p| p.file? } end |
#permanent_pathname ⇒ Object
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_pathname ⇒ Object
15 16 17 |
# File 'lib/mountable_file_server/file_accessor.rb', line 15 def temporary_pathname Pathname(configuration.storage_path) + 'tmp' + uid end |
#url ⇒ Object
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 |