Class: Jade::Registry
- Inherits:
-
Data
- Object
- Data
- Jade::Registry
- Defined in:
- lib/jade/registry.rb
Instance Attribute Summary collapse
-
#dependency_graph ⇒ Object
readonly
Returns the value of attribute dependency_graph.
-
#implementations ⇒ Object
readonly
Returns the value of attribute implementations.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#overlays ⇒ Object
readonly
Returns the value of attribute overlays.
-
#source_root ⇒ Object
readonly
Returns the value of attribute source_root.
Class Method Summary collapse
Instance Method Summary collapse
- #add_dependencies(entry, imports) ⇒ Object
- #add_module(entry) ⇒ Object
- #find_node_at(uri, offset) ⇒ Object
- #get(module_name) ⇒ Object
-
#initialize(modules: {}, implementations: {}, source_root: nil, dependency_graph: nil, overlays: {}) ⇒ Registry
constructor
A new instance of Registry.
- #lookup(symbol) ⇒ Object
- #modules_in_topo_order ⇒ Object
- #update_module(entry) ⇒ Object
Constructor Details
#initialize(modules: {}, implementations: {}, source_root: nil, dependency_graph: nil, overlays: {}) ⇒ Registry
Returns a new instance of Registry.
6 7 8 9 10 11 12 13 14 |
# File 'lib/jade/registry.rb', line 6 def initialize(modules: {}, implementations: {}, source_root: nil, dependency_graph: nil, overlays: {}) super( modules:, implementations:, source_root:, dependency_graph: dependency_graph || ModuleLoader::DependencyGraph.new, overlays:, ) end |
Instance Attribute Details
#dependency_graph ⇒ Object (readonly)
Returns the value of attribute dependency_graph
5 6 7 |
# File 'lib/jade/registry.rb', line 5 def dependency_graph @dependency_graph end |
#implementations ⇒ Object (readonly)
Returns the value of attribute implementations
5 6 7 |
# File 'lib/jade/registry.rb', line 5 def implementations @implementations end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules
5 6 7 |
# File 'lib/jade/registry.rb', line 5 def modules @modules end |
#overlays ⇒ Object (readonly)
Returns the value of attribute overlays
5 6 7 |
# File 'lib/jade/registry.rb', line 5 def @overlays end |
#source_root ⇒ Object (readonly)
Returns the value of attribute source_root
5 6 7 |
# File 'lib/jade/registry.rb', line 5 def source_root @source_root end |
Class Method Details
Instance Method Details
#add_dependencies(entry, imports) ⇒ Object
52 53 54 |
# File 'lib/jade/registry.rb', line 52 def add_dependencies(entry, imports) with(dependency_graph: dependency_graph.add(entry.name, imports)) end |
#add_module(entry) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jade/registry.rb', line 39 def add_module(entry) next_registry = with( modules: modules.merge(entry.name => entry), implementations: implementations.merge(entry.implementations), ) if entry.ast ModuleLoader::DependencyResolver.resolve(entry, next_registry) else next_registry end end |
#find_node_at(uri, offset) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/jade/registry.rb', line 56 def find_node_at(uri, offset) modules .each_value .find { it.source&.uri == uri } &.ast &.find_at(offset) end |
#get(module_name) ⇒ Object
26 27 28 |
# File 'lib/jade/registry.rb', line 26 def get(module_name) modules.dig(module_name) end |
#lookup(symbol) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/jade/registry.rb', line 64 def lookup(symbol) *module_parts, name = symbol.qualified_name.split('.') module_entry = module_parts.join('.').then { modules[it] } case symbol in Symbol::ValueRef module_entry.values[name] in Symbol::TypeRef module_entry.types[name] end end |
#modules_in_topo_order ⇒ Object
20 21 22 23 24 |
# File 'lib/jade/registry.rb', line 20 def modules_in_topo_order ModuleLoader::TopologicalSort .sort(dependency_graph) .map { get(it) } end |
#update_module(entry) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/jade/registry.rb', line 30 def update_module(entry) fail 'cannot update entry that does not exist' unless modules[entry.name] with( modules: modules.merge(entry.name => entry), implementations: implementations.merge(entry.implementations), ) end |