Class: ElFinderS3::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/el_finder_s3/adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Adapter

Returns a new instance of Adapter.



5
6
7
8
9
10
11
# File 'lib/el_finder_s3/adapter.rb', line 5

def initialize(server)
  @server = {
    response_cache_expiry_seconds: 3000
  }
  @cached_responses = {}
  @s3_connector = ElFinderS3::S3Connector.new server
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/el_finder_s3/adapter.rb', line 3

def connection
  @connection
end

#s3_connectorObject (readonly)

Returns the value of attribute s3_connector.



3
4
5
# File 'lib/el_finder_s3/adapter.rb', line 3

def s3_connector
  @s3_connector
end

#serverObject (readonly)

Returns the value of attribute server.



3
4
5
# File 'lib/el_finder_s3/adapter.rb', line 3

def server
  @server
end

Instance Method Details

#children(pathname, with_directory) ⇒ Object



21
22
23
24
25
# File 'lib/el_finder_s3/adapter.rb', line 21

def children(pathname, with_directory)
  cached :children, pathname do
    @s3_connector.ls_la(pathname, with_directory)
  end
end

#closeObject



17
18
19
# File 'lib/el_finder_s3/adapter.rb', line 17

def close
  true
end

#connectObject



13
14
15
# File 'lib/el_finder_s3/adapter.rb', line 13

def connect
  @connection
end

#delete(pathname) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/el_finder_s3/adapter.rb', line 126

def delete(pathname)
  #FIXME
  # ftp_context do
  #   ElFinderS3::Connector.logger.debug "  \e[1;32mFTP:\e[0m    Deleting #{pathname}"
  #   if pathname.directory?
  #     rmdir(pathname.to_s)
  #   else
  #     delete(pathname.to_s)
  #   end
  # end
  # clear_cache(pathname)
end

#exist?(pathname) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/el_finder_s3/adapter.rb', line 31

def exist?(pathname)
  cached :exist?, pathname do
    @s3_connector.exist? pathname
  end
end

#mkdir(pathname) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/el_finder_s3/adapter.rb', line 107

def mkdir(pathname)
  if @s3_connector.mkdir(pathname.to_prefix_s)
    #FIXME review cache clear
    # clear_cache(pathname)
    true
  else
    false
  end
end

#move(pathname, new_name) ⇒ Object

Both rename and move perform an FTP RNFR/RNTO (rename). Move differs because it first changes to the parent of the source pathname and uses a relative path for the RNFR. This seems to allow the (Microsoft) FTP server to rename a directory into another directory (e.g. /subdir/target -> /target )



97
98
99
100
101
102
103
104
105
# File 'lib/el_finder_s3/adapter.rb', line 97

def move(pathname, new_name)
  #FIXME
  # ftp_context(pathname.dirname) do
  #   ElFinderS3::Connector.logger.debug "  \e[1;32mFTP:\e[0m    Moving #{pathname} to #{new_name}"
  #   rename(pathname.basename.to_s, new_name.to_s)
  # end
  # clear_cache(pathname)
  # clear_cache(new_name)
end

#mtime(pathname) ⇒ Object

FIXME



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/el_finder_s3/adapter.rb', line 69

def mtime(pathname)
  cached :mtime, pathname do
    # ftp_context do
    #   ElFinderS3::Connector.logger.debug "  \e[1;32mFTP:\e[0m    Getting modified time of #{pathname}"
    #   begin
    #     mtime(pathname.to_s)
    #   rescue Net::FTPPermError => e
    # This command doesn't work on directories
    0
    # end
    # end
  end
end

#path_type(pathname) ⇒ Object

Parameters:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/el_finder_s3/adapter.rb', line 38

def path_type(pathname)
  cached :path_type, pathname do
    result = :directory
    begin
      if pathname.to_s == '/'
        result = :directory
      end
    rescue
      result = pathname[:type]
    end
    return result
  end
end

#rename(pathname, new_name) ⇒ Object

FIXME



84
85
86
87
88
89
90
# File 'lib/el_finder_s3/adapter.rb', line 84

def rename(pathname, new_name)
  # ftp_context do
  #   ElFinderS3::Connector.logger.debug "  \e[1;32mFTP:\e[0m    Renaming #{pathname} to #{new_name}"
  #   rename(pathname.to_s, new_name.to_s)
  # end
  # clear_cache(pathname)
end

#retrieve(pathname) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/el_finder_s3/adapter.rb', line 139

def retrieve(pathname)
  #FIXME
  # ftp_context do
  #   ElFinderS3::Connector.logger.debug "  \e[1;32mFTP:\e[0m    Retrieving #{pathname}"
  #   content = StringIO.new()
  #   begin
  #     retrbinary("RETR #{pathname}", 10240) do |block|
  #       content << block
  #     end
  #     content.string
  #   ensure
  #     content.close
  #   end
  # end
end

#rmdir(pathname) ⇒ Object



117
118
119
120
121
122
123
124
# File 'lib/el_finder_s3/adapter.rb', line 117

def rmdir(pathname)
  #FIXME
  # ftp_context do
  #   ElFinderS3::Connector.logger.debug "  \e[1;32mFTP:\e[0m    Removing directory #{pathname}"
  #   rmdir(pathname.to_s)
  # end
  # clear_cache(pathname)
end

#size(pathname) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/el_finder_s3/adapter.rb', line 52

def size(pathname)
  #FIXME
  # cached :size, pathname do
  #   ftp_context do
  #     ElFinderS3::Connector.logger.debug "  \e[1;32mFTP:\e[0m    Getting size of #{pathname}"
  #     begin
  #       size(pathname.to_s)
  #     rescue Net::FTPPermError => e
  #       nil
  #     rescue Net::FTPReplyError => e
  #       nil
  #     end
  #   end
  # end
end

#store(pathname, content) ⇒ Object



155
156
157
158
# File 'lib/el_finder_s3/adapter.rb', line 155

def store(pathname, content)
  @s3_connector.store(pathname.to_file_prefix_s, content)
  #TODO clear_cache(pathname)
end

#touch(pathname, options = {}) ⇒ Object



27
28
29
# File 'lib/el_finder_s3/adapter.rb', line 27

def touch(pathname, options={})
  @s3_connector.touch(pathname.to_file_prefix_s)
end