Class: Fog::Local::Storage::Files

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/local/models/files.rb

Instance Method Summary collapse

Instance Method Details

#allObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/local/models/files.rb', line 9

def all
  requires :directory
  if directory.collection.get(directory.key)
    data = []
    Dir.chdir(service.path_to(directory.key)) {
      data = Dir.glob('**/*').reject do |file|
        ::File.directory?(file)
      end.map do |key|
        path = file_path(key)
        {
          :content_length => ::File.size(path),
          :key            => key,
          :last_modified  => ::File.mtime(path)
        }
      end
    }
    load(data)
  else
    nil
  end
end

#get(key, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fog/local/models/files.rb', line 31

def get(key, &block)
  requires :directory
  path = file_path(key)
  if ::File.exist?(path)
    data = {
      :content_length => ::File.size(path),
      :key            => key,
      :last_modified  => ::File.mtime(path)
    }

    body = ""
    ::File.open(path) do |file|
      while (chunk = file.read(Excon::CHUNK_SIZE)) && (!block_given? || (block_given? && yield(chunk)))
        body << chunk
      end
    end
    data.merge!(:body => body) if !block_given?

    new(data)
  else
    nil
  end
end

#head(key) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/local/models/files.rb', line 55

def head(key)
  requires :directory
  path = file_path(key)
  if ::File.exist?(path)
    new({
      :content_length => ::File.size(path),
      :key            => key,
      :last_modified  => ::File.mtime(path)
    })
  else
    nil
  end
end

#is_truncatedObject



74
75
76
# File 'lib/fog/local/models/files.rb', line 74

def is_truncated
  false
end

#new(attributes = {}) ⇒ Object



69
70
71
72
# File 'lib/fog/local/models/files.rb', line 69

def new(attributes = {})
  requires :directory
  super({ :directory => directory }.merge!(attributes))
end