Class: RWGet::Store

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/rwget/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Store

Returns a new instance of Store.



7
8
9
# File 'lib/rwget/store.rb', line 7

def initialize(options = {})
  @root = "."
end

Instance Attribute Details

#rootObject

Returns the value of attribute root.



5
6
7
# File 'lib/rwget/store.rb', line 5

def root
  @root
end

Instance Method Details

#put(key, tmpfile) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rwget/store.rb', line 11

def put(key, tmpfile)
  path = File.join(@root, key)
  path = File.join(path, "index.html")     unless path.split("/").last =~ /\.|\?/
  dir = File.dirname(path)
  if(File.file?(dir))
    tmp = "#{dir}.index.html.#{Time.now.to_f}"
    mv dir, tmp
    mkdir_p(dir)
    mv tmp, File.join(dir, "index.html")
  else
    mkdir_p(dir)
  end
  mv tmpfile.path, path
end