class LanguageServer::FileStore
Attributes
load_paths[R]
local_root[R]
remote_root[R]
Public Class Methods
new(load_paths: [], remote_root: Dir.getwd, local_root: Dir.getwd)
click to toggle source
# File lib/language_server/file_store.rb, line 39 def initialize(load_paths: [], remote_root: Dir.getwd, local_root: Dir.getwd) @load_paths = load_paths @remote_root = remote_root @local_root = local_root end
Public Instance Methods
cache(remote_uri, content)
click to toggle source
# File lib/language_server/file_store.rb, line 45 def cache(remote_uri, content) cache_store[path_from_remote_uri(remote_uri)] = content end
each() { |read(path), path| ... }
click to toggle source
# File lib/language_server/file_store.rb, line 65 def each(&block) all_paths.each do |path| yield(read(path), path) end end
path_from_remote_uri(remote_uri)
click to toggle source
# File lib/language_server/file_store.rb, line 49 def path_from_remote_uri(remote_uri) FilePath.from_remote_uri(local_root: local_root, remote_root: remote_root, remote_uri: remote_uri) end
read(path)
click to toggle source
# File lib/language_server/file_store.rb, line 53 def read(path) if exists_on_cache?(path) read_from_cache(path) else read_from_local(path) end end
read_remote_uri(remote_uri)
click to toggle source
# File lib/language_server/file_store.rb, line 61 def read_remote_uri(remote_uri) read(path_from_remote_uri(remote_uri)) end
Private Instance Methods
all_paths()
click to toggle source
# File lib/language_server/file_store.rb, line 75 def all_paths (cache_store.keys + load_paths.flat_map { |path| Dir.glob(File.join(path, "**", "*.rb")) }.map { |path| FilePath.new(local_root: local_root, remote_root: remote_root, local_path: path) }).uniq end
cache_store()
click to toggle source
# File lib/language_server/file_store.rb, line 95 def cache_store @cache_store ||= {} end
exists_on_cache?(path)
click to toggle source
# File lib/language_server/file_store.rb, line 83 def exists_on_cache?(path) cache_store.has_key?(path) end
read_from_cache(path)
click to toggle source
# File lib/language_server/file_store.rb, line 87 def read_from_cache(path) cache_store[path] end
read_from_local(path)
click to toggle source
# File lib/language_server/file_store.rb, line 91 def read_from_local(path) File.read(path.local_path) end