Sha256: c43f3a6d72268b7326f6fb541bc5deb699c6fcd2244f4a99750c8313ed635105

Contents?: true

Size: 1.73 KB

Versions: 15

Compression:

Stored size: 1.73 KB

Contents

module BrowseEverything
  module Driver
    class FileSystem < Base

      def icon
        'file'
      end
      
      def validate_config
        unless config[:home]
          raise BrowseEverything::InitializationError, "FileSystem driver requires a :home argument"
        end
      end

      def contents(path='')
        relative_path = path.sub(%r{^[\/.]+},'')
        real_path = File.join(config[:home], relative_path)
        result = []
        if File.directory?(real_path)
          if relative_path.present?
            result << details(File.expand_path('..',real_path),'..')
          end
          result += Dir[File.join(real_path,'*')].collect { |f| details(f) }
        elsif File.exists?(real_path)
          result += [details(real_path)]
        end
        result.sort do |a,b|
          if b.container?
            a.container? ? a.name.downcase <=> b.name.downcase : 1
          else
            a.container? ? -1 : a.name.downcase <=> b.name.downcase
          end
        end
      end

      def details(path,display=nil)
        if File.exists?(path)
          info = File::Stat.new(path)
          BrowseEverything::FileEntry.new(
            Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(config[:home])),
            [self.key,path].join(':'),
            display || File.basename(path),
            info.size,
            info.mtime,
            info.directory?
          )
        else
          nil
        end
      end

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

      def authorized?
        true
      end
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
browse-everything-0.10.5 lib/browse_everything/driver/file_system.rb
browse-everything-0.10.4 lib/browse_everything/driver/file_system.rb
browse-everything-0.10.3 lib/browse_everything/driver/file_system.rb
browse-everything-0.10.2 lib/browse_everything/driver/file_system.rb
browse-everything-0.10.1 lib/browse_everything/driver/file_system.rb
browse-everything-0.10.0 lib/browse_everything/driver/file_system.rb
browse-everything-0.9.1 lib/browse_everything/driver/file_system.rb
browse-everything-0.9.0 lib/browse_everything/driver/file_system.rb
browse-everything-0.8.4 lib/browse_everything/driver/file_system.rb
browse-everything-0.8.3 lib/browse_everything/driver/file_system.rb
browse-everything-0.8.2 lib/browse_everything/driver/file_system.rb
browse-everything-0.8.1 lib/browse_everything/driver/file_system.rb
browse-everything-0.8.0 lib/browse_everything/driver/file_system.rb
browse-everything-0.7.1 lib/browse_everything/driver/file_system.rb
browse-everything-0.7.0 lib/browse_everything/driver/file_system.rb