Class: Universa::FSStore::FileStore
- Inherits:
-
ChainStore
- Object
- ChainStore
- Universa::FSStore::FileStore
- Defined in:
- lib/universa/fs_store/file_store.rb
Overview
Simple file-based store that could be efficiently user with per-file cloud storages like Dropbox, Google Disk, NextCloud and like.
Notes to developers:
-
attributes are eager loaded: should always be contructed from contract or from file
-
contract is lazy loaded
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
- String
-
The file store root path.
Instance Method Summary collapse
-
#count ⇒ Object
Count contracts in the store.
-
#find_by_id(hash_id) ⇒ Contract
With the corresponding id or nil.
-
#initialize(root_path) ⇒ FileStore
constructor
Construct store in the path supplied.
-
#store_contract(contract) ⇒ StoredContract
Save contract to the store.
Methods inherited from ChainStore
#<<, #find_by_id!, #find_by_parent
Constructor Details
#initialize(root_path) ⇒ FileStore
Construct store in the path supplied. If the path is not empty, it will be scanned for stored contracts.
21 22 23 24 25 |
# File 'lib/universa/fs_store/file_store.rb', line 21 def initialize(root_path) @root = root_path @root = @root[0...-1] while (@root[-1] == '/') init_cache end |
Instance Attribute Details
#root ⇒ Object (readonly)
- String
-
The file store root path
17 18 19 |
# File 'lib/universa/fs_store/file_store.rb', line 17 def root @root end |
Instance Method Details
#count ⇒ Object
Count contracts in the store. This operation could be slow.
40 41 42 |
# File 'lib/universa/fs_store/file_store.rb', line 40 def count @cache.size end |
#find_by_id(hash_id) ⇒ Contract
Returns with the corresponding id or nil.
35 36 37 |
# File 'lib/universa/fs_store/file_store.rb', line 35 def find_by_id hash_id @cache[hash_id] end |
#store_contract(contract) ⇒ StoredContract
Save contract to the store. When this method returns, the contract must me already stored. If the contract with such hasId is already stored, just returns it.
28 29 30 31 32 |
# File 'lib/universa/fs_store/file_store.rb', line 28 def store_contract contract entry = FSStore::Entry.new(self) entry = entry.init_with_contract(contract) add_to_cache entry end |