Class: Fog::External::Backend::Local
- Inherits:
-
Object
- Object
- Fog::External::Backend::Local
- Defined in:
- lib/fog/external/backend/local.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_directory(key) ⇒ Object
- #destroy_directory(key) ⇒ Object
- #destroy_file(key) ⇒ Object
- #get_directory(key) ⇒ Object
- #get_file(key) ⇒ Object
- #head_file(key) ⇒ Object
-
#initialize(root) ⇒ Local
constructor
A new instance of Local.
- #list_directories ⇒ Object
- #list_files(dir_key) ⇒ Object
- #save_file(key, body) ⇒ Object
Constructor Details
Class Method Details
.act_as_ernie_handler!(root = '/tmp/fog-bertrpc-handler') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/external/backend/local.rb', line 8 def self.act_as_ernie_handler!(root = '/tmp/fog-bertrpc-handler') require 'ernie' instance = self.new(root) mod = Module.new do instance.methods.each do |m| define_method m do |*args| instance.send m, *args end end end Ernie.expose(:fog, mod) end |
Instance Method Details
#create_directory(key) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/fog/external/backend/local.rb', line 27 def create_directory(key) if ::File.directory?(path_to(key)) false else Dir.mkdir path_to(key) end end |
#destroy_directory(key) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/fog/external/backend/local.rb', line 51 def destroy_directory(key) if ::File.directory?(path_to(key)) Dir.rmdir(path_to(key)) true else false end end |
#destroy_file(key) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/fog/external/backend/local.rb', line 105 def destroy_file(key) path = path_to(key) if ::File.exists?(path) ::File.delete(path) true else false end end |
#get_directory(key) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/fog/external/backend/local.rb', line 43 def get_directory(key) if ::File.directory?(path_to(key)) { key: key } else nil end end |
#get_file(key) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fog/external/backend/local.rb', line 91 def get_file(key) path = path_to(key) if ::File.exists?(path) { :content_length => ::File.size(path), :key => key, :last_modified => ::File.mtime(path), :body => ::File.read(path) } else nil end end |
#head_file(key) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fog/external/backend/local.rb', line 78 def head_file(key) path = path_to(key) if ::File.exists?(path) { :content_length => ::File.size(path), :key => key, :last_modified => ::File.mtime(path) } else nil end end |
#list_directories ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/fog/external/backend/local.rb', line 35 def list_directories data = Dir.entries(@root).select do |entry| entry[0...1] != '.' && ::File.directory?(path_to(entry)) end.map do |entry| {:key => entry} end end |
#list_files(dir_key) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fog/external/backend/local.rb', line 61 def list_files(dir_key) data = nil Dir.chdir(path_to(dir_key)) do data = Dir.glob('**/*').reject do |file| ::File.directory?(file) end.map do |key| path = path_to(key) { :content_length => ::File.size(path), :key => key, :last_modified => ::File.mtime(path) } end end data end |
#save_file(key, body) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fog/external/backend/local.rb', line 116 def save_file(key, body) path = path_to(key) ::FileUtils.mkdir_p(File.dirname(path)) file = ::File.new(path, 'wb') file.write(body) file.close ::File.mtime(path) end |