Class: Staticd::Datastores::Local
- Inherits:
-
Object
- Object
- Staticd::Datastores::Local
- Defined in:
- lib/staticd/datastores/local.rb
Overview
Datastore storing files on local directory.
It use the file SHA1 digest as a filename so two identical files are not stored twice.
Example:
datastore = Staticd::Datastores::Local.new(path: "/tmp/datastore")
datastore.put(file_path) unless datastore.exist?(file_path)
# => "/tmp/datastore/sha1_digest"
Instance Method Summary collapse
- #exist?(file_path) ⇒ Boolean
-
#initialize(params) ⇒ Local
constructor
A new instance of Local.
- #put(file_path) ⇒ Object
Constructor Details
#initialize(params) ⇒ Local
Returns a new instance of Local.
17 18 19 20 |
# File 'lib/staticd/datastores/local.rb', line 17 def initialize(params) @path = params[:path] check_store_directory end |
Instance Method Details
#exist?(file_path) ⇒ Boolean
28 29 30 31 |
# File 'lib/staticd/datastores/local.rb', line 28 def exist?(file_path) datastore_file = stored_file_path(file_path) File.exist?(datastore_file) ? datastore_file : false end |
#put(file_path) ⇒ Object
22 23 24 25 26 |
# File 'lib/staticd/datastores/local.rb', line 22 def put(file_path) datastore_file = stored_file_path(file_path) FileUtils.copy_file(file_path, datastore_file) unless exist?(file_path) datastore_file end |