Class: Dassets::FileStore
- Inherits:
-
Object
- Object
- Dassets::FileStore
- Defined in:
- lib/dassets/file_store.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NullStore
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, &block) ⇒ Object
- #store_path(url) ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/dassets/file_store.rb', line 6 def root @root end |
Instance Method Details
#save(url, &block) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/dassets/file_store.rb', line 13 def save(url, &block) @save_mutex.synchronize do store_path(url).tap do |path| FileUtils.mkdir_p(File.dirname(path)) File.open(path, "w"){ |f| f.write(block.call) } end end end |
#store_path(url) ⇒ Object
22 23 24 |
# File 'lib/dassets/file_store.rb', line 22 def store_path(url) File.join(@root, url) end |