Class: Yoda::Server::Session
- Inherits:
-
Object
- Object
- Yoda::Server::Session
- Defined in:
- lib/yoda/server/session.rb
Instance Attribute Summary collapse
- #workspaces ⇒ Array<Workspace> readonly
Class Method Summary collapse
Instance Method Summary collapse
- #add_workspace(new_workspace) ⇒ Object
-
#initialize(workspaces:) ⇒ Session
constructor
A new instance of Session.
- #project ⇒ Store::Project?
- #read_source(uri) ⇒ Object (also: #reparse_doc)
- #registry ⇒ Store::Registry
- #remove_source(uri:) ⇒ Object
- #remove_workspace(id:) ⇒ Object
-
#setup ⇒ Array<Exception>
Errors on setup.
- #store_source(uri:, source:) ⇒ Object
- #temporal_workspace_for(uri) ⇒ Object
- #workspace_for(uri) ⇒ Workspace?
- #workspaces_for(uri) ⇒ Array<Workspace>
Constructor Details
#initialize(workspaces:) ⇒ Session
Returns a new instance of Session.
22 23 24 |
# File 'lib/yoda/server/session.rb', line 22 def initialize(workspaces:) @workspaces = workspaces end |
Instance Attribute Details
#workspaces ⇒ Array<Workspace> (readonly)
7 8 9 |
# File 'lib/yoda/server/session.rb', line 7 def workspaces @workspaces end |
Class Method Details
.from_root_uri(root_uri) ⇒ Object
9 10 11 12 13 |
# File 'lib/yoda/server/session.rb', line 9 def self.from_root_uri(root_uri) workspaces = [Workspace.new(name: 'root', root_uri: root_uri)] Logger.trace("Setting up session for #{root_uri}") new(workspaces: workspaces) end |
.from_workspace_folders(workspace_folders) ⇒ Object
16 17 18 19 |
# File 'lib/yoda/server/session.rb', line 16 def self.from_workspace_folders(workspace_folders) workspaces = workspace_folders.map { |folder| Workspace.from_workspace_folder(folder) } new(workspaces: workspaces) end |
Instance Method Details
#add_workspace(new_workspace) ⇒ Object
37 38 39 40 41 |
# File 'lib/yoda/server/session.rb', line 37 def add_workspace(new_workspace) return if workspaces.find { |workspace| workspace.id == new_workspace.id } new_workspace.setup workspaces.push(new_workspace) end |
#project ⇒ Store::Project?
49 50 51 |
# File 'lib/yoda/server/session.rb', line 49 def project workspaces.first&.project end |
#read_source(uri) ⇒ Object Also known as: reparse_doc
53 54 55 |
# File 'lib/yoda/server/session.rb', line 53 def read_source(uri) workspaces_for(uri).each { |workspace| workspace.read_source(uri) } end |
#registry ⇒ Store::Registry
27 28 29 |
# File 'lib/yoda/server/session.rb', line 27 def registry project.registry end |
#remove_source(uri:) ⇒ Object
65 66 67 |
# File 'lib/yoda/server/session.rb', line 65 def remove_source(uri:) workspaces_for(uri).each { |workspace| workspace.remove_source(uri: uri) } end |
#remove_workspace(id:) ⇒ Object
44 45 46 |
# File 'lib/yoda/server/session.rb', line 44 def remove_workspace(id:) @workspaces = workspaces.reject { |workspace| workspace.id == id } end |
#setup ⇒ Array<Exception>
Returns errors on setup.
32 33 34 |
# File 'lib/yoda/server/session.rb', line 32 def setup workspaces.flat_map(&:setup) end |
#store_source(uri:, source:) ⇒ Object
60 61 62 |
# File 'lib/yoda/server/session.rb', line 60 def store_source(uri:, source:) workspaces_for(uri).each { |workspace| workspace.store_source(uri: uri, source: source) } end |
#temporal_workspace_for(uri) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/yoda/server/session.rb', line 80 def temporal_workspace_for(uri) temporal_workspaces[uri] ||= RootlessWorkspace.new(name: uri).tap do |workspace| Logger.trace "Setting up temporal workspace for #{uri}" workspace.setup # Store the file content to the temporally workspace workspace.read_source(uri) end end |
#workspace_for(uri) ⇒ Workspace?
70 71 72 |
# File 'lib/yoda/server/session.rb', line 70 def workspace_for(uri) workspaces_for(uri).first end |
#workspaces_for(uri) ⇒ Array<Workspace>
75 76 77 78 |
# File 'lib/yoda/server/session.rb', line 75 def workspaces_for(uri) matched_workspaces = workspaces.select { |workspace| workspace.suburi?(uri) } matched_workspaces.empty? ? [temporal_workspace_for(uri)] : matched_workspaces end |