Class: Dassets::FileStore
- Inherits:
-
Object
- Object
- Dassets::FileStore
- Defined in:
- lib/dassets/file_store.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root) ⇒ FileStore
constructor
A new instance of FileStore.
- #save(url_path, &block) ⇒ Object
- #store_path(url_path) ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
8 9 10 |
# File 'lib/dassets/file_store.rb', line 8 def root @root end |
Instance Method Details
#save(url_path, &block) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/dassets/file_store.rb', line 15 def save(url_path, &block) @save_mutex.synchronize do store_path(url_path).tap do |path| FileUtils.mkdir_p(File.dirname(path)) File.open(path, "wb"){ |f| f.write(block.call) } end end end |
#store_path(url_path) ⇒ Object
24 25 26 |
# File 'lib/dassets/file_store.rb', line 24 def store_path(url_path) File.join(@root, url_path) end |