Class: Whoosh::Storage::Local
- Inherits:
-
Object
- Object
- Whoosh::Storage::Local
- Defined in:
- lib/whoosh/storage/local.rb
Instance Method Summary collapse
-
#initialize(root:) ⇒ Local
constructor
A new instance of Local.
- #save(uploaded_file, prefix = "") ⇒ Object
Constructor Details
Instance Method Details
#save(uploaded_file, prefix = "") ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/whoosh/storage/local.rb', line 14 def save(uploaded_file, prefix = "") dir = prefix.empty? ? @root : File.join(@root, prefix) FileUtils.mkdir_p(dir) filename = "#{SecureRandom.uuid}_#{uploaded_file.filename}" path = File.join(dir, filename) File.open(path, "wb") { |f| f.write(uploaded_file.read) } prefix.empty? ? filename : File.join(prefix, filename) end |