Class: BrowseEverything::Driver::FileSystem

Inherits:
Base
  • Object
show all
Defined in:
lib/browse_everything/driver/file_system.rb

Instance Attribute Summary

Attributes inherited from Base

#code, #token

Instance Method Summary collapse

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

Returns:

  • (Boolean)


39
40
41
# File 'lib/browse_everything/driver/file_system.rb', line 39

def authorized?
  true
end

#contents(path = '') ⇒ Array<BrowseEverything::FileEntry>

Retrieve the contents of a directory

Parameters:

  • path (String) (defaults to: '')

    the path to a file system resource

Returns:



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

Parameters:

  • path (String)

    path to the file

  • display (String) (defaults to: File.basename(path))

    display label for the resource

Returns:



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

#iconObject



6
7
8
# File 'lib/browse_everything/driver/file_system.rb', line 6

def icon
  'file'
end


33
34
35
36
37
# File 'lib/browse_everything/driver/file_system.rb', line 33

def link_for(path)
  full_path = File.expand_path(path)
  file_size = file_size(full_path)
  ["file://#{full_path}", { file_name: File.basename(path), file_size: file_size }]
end

#validate_configObject



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