class Universa::FSStore::FileStore
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
Attributes
root[R]
- String
-
The file store root path
Public Class Methods
new(root_path)
click to toggle source
Construct store in the path supplied. If the path is not empty, it will be scanned for stored contracts. @param [String] root_path of the store, must exist.
# 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
Public Instance Methods
count()
click to toggle source
(see ChainStore#count
)
# File lib/universa/fs_store/file_store.rb, line 40 def count @cache.size end
find_by_id(hash_id)
click to toggle source
(see ChainStore#find_by_id
)
# File lib/universa/fs_store/file_store.rb, line 35 def find_by_id hash_id @cache[hash_id] end
store_contract(contract)
click to toggle source
(see ChainStore#store_contract
)
# 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
Protected Instance Methods
add_to_cache(entry)
click to toggle source
add single entry to the cache @param [Entry] entry to add. Could have contract not yet loaded but should be configured with attributes.
# File lib/universa/fs_store/file_store.rb, line 56 def add_to_cache(entry) raise ArgumentError, "entry can't be nil" unless entry @cache[entry.hash_id] = entry end
init_cache()
click to toggle source
scan the root folder for attribute files and store them in the cache
# File lib/universa/fs_store/file_store.rb, line 47 def init_cache @cache = {} Dir[@root + "/*.unicon.yaml"].each {|name| add_to_cache Entry.new(self).load_from_yaml_file(name) } end