Class: ElFinderFtp::FtpPathname

Inherits:
Pathname
  • Object
show all
Defined in:
lib/el_finder_ftp/ftp_pathname.rb

Instance Attribute Summary collapse

Attributes inherited from Pathname

#path, #root

Instance Method Summary collapse

Methods inherited from Pathname

#absolute?, #basename, #basename_sans_extension, #child_directories, #children, #dirname, #duplicate, #extname, #files, #fullpath, #is_root?, #outside_of_root?, #relative?, #relative_to, #to_s, #unique

Constructor Details

#initialize(adapter, list_entry_or_name, attrs = {}) ⇒ FtpPathname

Returns a new instance of FtpPathname.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 5

def initialize(adapter, list_entry_or_name, attrs = {})
  @adapter = adapter

  if list_entry_or_name.is_a? ElFinderFtp::FtpPathname
    super(list_entry_or_name.to_s)
    self.attrs = list_entry_or_name.attrs
  elsif list_entry_or_name.is_a? Net::FTP::List::Entry
    super(list_entry_or_name.basename)
    
    if list_entry_or_name.dir?
      @size = 0
      @type = :directory
    else
      @type = :file
      @size = list_entry_or_name.filesize
    end
    
    @time = list_entry_or_name.mtime
  else
    super(list_entry_or_name)
    self.attrs = attrs
  end
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



3
4
5
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 3

def adapter
  @adapter
end

Instance Method Details

#+(other) ⇒ Object



29
30
31
32
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 29

def +(other)
  other = FtpPathname.new(adapter, other) unless FtpPathname === other
  FtpPathname.new(adapter, plus(@path, other.to_s), other.attrs)
end

#atimeObject



47
48
49
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 47

def atime
  mtime
end

#attrsObject



34
35
36
37
38
39
40
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 34

def attrs
  {
    type: @type,
    time: @time,
    size: @size
  }
end

#attrs=(val) ⇒ Object



41
42
43
44
45
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 41

def attrs=(val)
  @time = val[:time]
  @type = val[:type]
  @size = val[:size]      
end

#cleanpathObject



59
60
61
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 59

def cleanpath
  self
end

#ctimeObject



51
52
53
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 51

def ctime
  mtime
end

#directory?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 67

def directory?
  type == :directory
end

#executable?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 136

def executable?
  false
end

#exist?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 63

def exist?
  adapter.exist?( self )
end

#file?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 83

def file?
  type == :file
end

#ftypeObject



91
92
93
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 91

def ftype
  type.to_s
end

#mkdirObject



113
114
115
116
117
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 113

def mkdir
  adapter.mkdir(self)
  @type = :directory
  @size = 0
end

#mtimeObject



55
56
57
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 55

def mtime
  @time ||= adapter.mtime(self)
end

#pipe?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 140

def pipe?
  false
end

#readObject



127
128
129
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 127

def read
  adapter.retrieve(self)
end

#readable?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 71

def readable?
  true
end

#realpathObject



87
88
89
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 87

def realpath
  self
end

#rename(to) ⇒ Object



109
110
111
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 109

def rename(to)
  adapter.rename(self, to)
end

#rmdirObject



119
120
121
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 119

def rmdir
  adapter.rmdir(self)
end

#sizeObject



99
100
101
102
103
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 99

def size
  unless @type == :directory
    @size ||= adapter.size(self)
  end
end

#symlink?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 79

def symlink?
  false
end

#touchObject



105
106
107
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 105

def touch
  adapter.touch(self)
end

#typeObject



95
96
97
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 95

def type
  @type ||= adapter.path_type(self)
end


123
124
125
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 123

def unlink
  adapter.delete(self)
end

#writable?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 75

def writable?
  true
end

#write(content) ⇒ Object



131
132
133
134
# File 'lib/el_finder_ftp/ftp_pathname.rb', line 131

def write(content)
  adapter.store(self, content)
  @size = nil
end