Class: ElFinderS3::Adapter
- Inherits:
-
Object
- Object
- ElFinderS3::Adapter
- Defined in:
- lib/el_finder_s3/adapter.rb
Instance Attribute Summary collapse
-
#s3_connector ⇒ Object
readonly
Returns the value of attribute s3_connector.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #children(pathname, with_directory) ⇒ Object
- #close ⇒ Object
- #delete(pathname) ⇒ Object
- #exist?(pathname) ⇒ Boolean
-
#initialize(server, cache_connector) ⇒ Adapter
constructor
A new instance of Adapter.
- #mkdir(pathname) ⇒ Object
-
#move(pathname, new_name) ⇒ Object
Both rename and move perform an FTP RNFR/RNTO (rename).
-
#mtime(pathname) ⇒ Object
FIXME.
- #path_type(pathname) ⇒ Object
-
#rename(pathname, new_name) ⇒ Object
FIXME.
- #retrieve(pathname) ⇒ Object
- #rmdir(pathname) ⇒ Object
- #size(pathname) ⇒ Object
- #store(pathname, content) ⇒ Object
- #touch(pathname, options = {}) ⇒ Object
Constructor Details
#initialize(server, cache_connector) ⇒ Adapter
Returns a new instance of Adapter.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/el_finder_s3/adapter.rb', line 8 def initialize(server, cache_connector) @server = { response_cache_expiry_seconds: 3000 } @cached_responses = {} @s3_connector = ElFinderS3::S3Connector.new server @cache_connector = cache_connector.nil? ? ElFinderS3::CacheConnector.new : @cache_connector = cache_connector # client = Memcached.new('127.0.0.1:11211', :binary_protocol => true) # @cache = Cache.wrap(client) end |
Instance Attribute Details
#s3_connector ⇒ Object (readonly)
Returns the value of attribute s3_connector.
6 7 8 |
# File 'lib/el_finder_s3/adapter.rb', line 6 def s3_connector @s3_connector end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
6 7 8 |
# File 'lib/el_finder_s3/adapter.rb', line 6 def server @server end |
Instance Method Details
#children(pathname, with_directory) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/el_finder_s3/adapter.rb', line 23 def children(pathname, with_directory) elements = @cache_connector.cached ElFinderS3::Operations::CHILDREN, pathname do @s3_connector.ls_la(pathname) end result = [] elements[:folders].each { |folder| result.push(pathname.fullpath + ElFinderS3::S3Pathname.new(@s3_connector, folder, {:type => :directory})) } elements[:files].each { |file| if with_directory result.push(pathname.fullpath + ElFinderS3::S3Pathname.new(@s3_connector, file, {:type => :file})) else result.push(ElFinderS3::S3Pathname.new(@s3_connector, file, {:type => :file})) end } result end |
#close ⇒ Object
19 20 21 |
# File 'lib/el_finder_s3/adapter.rb', line 19 def close true end |
#delete(pathname) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/el_finder_s3/adapter.rb', line 120 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
49 50 51 52 53 |
# File 'lib/el_finder_s3/adapter.rb', line 49 def exist?(pathname) @cache_connector.cached ElFinderS3::Operations::EXIST, pathname do @s3_connector.exist? pathname end end |
#mkdir(pathname) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/el_finder_s3/adapter.rb', line 103 def mkdir(pathname) if @s3_connector.mkdir(pathname.to_prefix_s) @cache_connector.clear_cache(pathname) 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 )
93 94 95 96 97 98 99 100 101 |
# File 'lib/el_finder_s3/adapter.rb', line 93 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
72 73 74 75 76 77 |
# File 'lib/el_finder_s3/adapter.rb', line 72 def mtime(pathname) @cache_connector.cached ElFinderS3::Operations::MTIME, pathname do #mtime(pathname.to_s) 0 end end |
#path_type(pathname) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/el_finder_s3/adapter.rb', line 55 def path_type(pathname) @cache_connector.cached ElFinderS3::Operations::PATH_TYPE, pathname do result = :directory if pathname.to_s == '/' result = :directory end result end end |
#rename(pathname, new_name) ⇒ Object
FIXME
80 81 82 83 84 85 86 |
# File 'lib/el_finder_s3/adapter.rb', line 80 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
133 134 135 |
# File 'lib/el_finder_s3/adapter.rb', line 133 def retrieve(pathname) @s3_connector.get(pathname.to_file_prefix_s) end |
#rmdir(pathname) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/el_finder_s3/adapter.rb', line 111 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
65 66 67 68 69 |
# File 'lib/el_finder_s3/adapter.rb', line 65 def size(pathname) @cache_connector.cached :size, pathname do @s3_connector.size(pathname) end end |
#store(pathname, content) ⇒ Object
137 138 139 140 |
# File 'lib/el_finder_s3/adapter.rb', line 137 def store(pathname, content) @s3_connector.store(pathname.to_file_prefix_s, content) #TODO clear_cache(pathname) end |
#touch(pathname, options = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/el_finder_s3/adapter.rb', line 42 def touch(pathname, ={}) if @s3_connector.touch(pathname.to_file_prefix_s) @cache_connector.clear_cache(pathname, false) true end end |