Class: SkadateGems::Dev::Remote::Directory
- Defined in:
- lib/skadategems/dev/remote/directory.rb
Overview
Represents a remote directory.
Instance Attribute Summary collapse
Attributes inherited from File
Instance Method Summary collapse
-
#directory? ⇒ boolean
Always true.
-
#extname ⇒ String
Always ‘/’.
-
#list ⇒ Array < Directory | File >
List remote directory files.
Methods inherited from File
#basename, #friendly_size, #initialize, #request, #save_as
Constructor Details
This class inherits a constructor from SkadateGems::Dev::Remote::File
Instance Attribute Details
#list_hidden ⇒ Object
13 14 15 |
# File 'lib/skadategems/dev/remote/directory.rb', line 13 def list_hidden @list_hidden end |
Instance Method Details
#directory? ⇒ boolean
Returns always true.
16 17 18 |
# File 'lib/skadategems/dev/remote/directory.rb', line 16 def directory? true end |
#extname ⇒ String
Returns always ‘/’.
21 22 23 |
# File 'lib/skadategems/dev/remote/directory.rb', line 21 def extname '/' end |
#list ⇒ Array < Directory | File >
List remote directory files.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/skadategems/dev/remote/directory.rb', line 28 def list path = self.path.dup path[0] = '' if path[0] == '/' path[-1] = '' if path[-1] == '/' response = @remote.exec do |batch| batch << <<-PHPSCRIPT $dir = dir(DIR_SITE_ROOT . '#{path.gsub(/['\\]/, '\\\\\0')}'); $list = array(); while (false !== ($file = $dir->read())) { if (#{if list_hidden '$file === \'.\' || $file === \'..\'' else '$file{0} === \'.\' && $file !== \'.htaccess\'' end}) { continue; } $path = "$dir->path/$file"; if ($path === $_SERVER['SCRIPT_FILENAME']) { continue; } if (is_file($path)) { $type = 'f'; } elseif (is_dir($path)) { $type = 'd'; } else { continue; } $list[] = array($file, $type, filesize($path)); } echo json_encode($list); PHPSCRIPT end result = [] JSON.parse(response.body).each do |entry| name, type, size = entry _path = ::File.join(self.path, name) result << if type == 'd' Directory.new(@remote, _path, size) else File.new(@remote, _path, size) end end result.sort! { |a, b| a.basename <=> b.basename } end |