Class: Dassets::FileStore

Inherits:
Object
  • Object
show all
Defined in:
lib/dassets/file_store.rb

Direct Known Subclasses

NullStore

Defined Under Namespace

Classes: NullStore

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ FileStore



8
9
10
11
# File 'lib/dassets/file_store.rb', line 8

def initialize(root)
  @root = root
  @save_mutex = ::Mutex.new
end

Instance Attribute Details

#rootObject (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