Class: BrowseEverything::Driver::FileSystem
- Defined in:
- lib/browse_everything/driver/file_system.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #authorized? ⇒ Boolean
-
#contents(path = '') ⇒ Array<BrowseEverything::FileEntry>
Retrieve the contents of a directory.
-
#details(path, display = File.basename(path)) ⇒ BrowseEverything::FileEntry
Construct a FileEntry objects for a file-system resource.
- #icon ⇒ Object
- #link_for(path) ⇒ Object
- #validate_config ⇒ Object
Methods inherited from Base
#auth_link, #config, #connect, default_sorter, inherited, #initialize, #key, #name
Constructor Details
This class inherits a constructor from BrowseEverything::Driver::Base
Instance Method Details
#authorized? ⇒ Boolean
39 40 41 |
# File 'lib/browse_everything/driver/file_system.rb', line 39 def true end |
#contents(path = '') ⇒ Array<BrowseEverything::FileEntry>
Retrieve the contents of a directory
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/browse_everything/driver/file_system.rb', line 21 def contents(path = '') real_path = File.join(home_path, path) values = if File.directory?(real_path) make_directory_entry real_path else [details(real_path)] end @entries = values.compact @sorter.call(@entries) end |
#details(path, display = File.basename(path)) ⇒ BrowseEverything::FileEntry
Construct a FileEntry objects for a file-system resource
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/browse_everything/driver/file_system.rb', line 47 def details(path, display = File.basename(path)) return nil unless File.exist? path info = File::Stat.new(path) BrowseEverything::FileEntry.new( make_pathname(path), [key, path].join(':'), display, info.size, info.mtime, info.directory? ) end |
#icon ⇒ Object
6 7 8 |
# File 'lib/browse_everything/driver/file_system.rb', line 6 def icon 'file' end |
#link_for(path) ⇒ Object
33 34 35 36 37 |
# File 'lib/browse_everything/driver/file_system.rb', line 33 def link_for(path) full_path = File.(path) file_size = file_size(full_path) ["file://#{full_path}", { file_name: File.basename(path), file_size: file_size }] end |
#validate_config ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/browse_everything/driver/file_system.rb', line 10 def validate_config raise BrowseEverything::InitializationError, 'FileSystem driver requires a :home argument' if config[:home].blank? unless config[:home].start_with?("/") || config[:allow_relative_home] == true raise BrowseEverything::InitializationError, 'FileSystem driver :home argument must be absolute unless :allow_relative_home is set' end end |