Class: Jade::Api
- Inherits:
-
Data
- Object
- Data
- Jade::Api
- Defined in:
- lib/jade/api.rb
Overview
The public surface of everything a module can call, read from the registry rather than the source. Stdlib modules are written both as Jade heredocs and as a Ruby DSL, and an extension gem's modules aren't in the tree at all, so no grep of the source finds them.
Constant Summary collapse
- ORIGIN_ORDER =
{ 'project' => 0, 'extension' => 1, 'stdlib' => 2 }.freeze
- KIND_ORDER =
{ 'type' => 0, 'struct' => 0, 'interface' => 1, 'constructor' => 2, 'function' => 3, }.freeze
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#skipped ⇒ Object
readonly
Returns the value of attribute skipped.
-
#source_root ⇒ Object
readonly
Returns the value of attribute source_root.
Class Method Summary collapse
Instance Method Summary collapse
- #describe(module_name) ⇒ Object
- #lookup(qualified_name) ⇒ Object
- #modules ⇒ Object
- #search(term) ⇒ Object
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry
10 11 12 |
# File 'lib/jade/api.rb', line 10 def registry @registry end |
#skipped ⇒ Object (readonly)
Returns the value of attribute skipped
10 11 12 |
# File 'lib/jade/api.rb', line 10 def skipped @skipped end |
#source_root ⇒ Object (readonly)
Returns the value of attribute source_root
10 11 12 |
# File 'lib/jade/api.rb', line 10 def source_root @source_root end |
Class Method Details
.load(project = Project.find) ⇒ Object
11 12 13 |
# File 'lib/jade/api.rb', line 11 def self.load(project = Project.find) project ? of_project(project) : stdlib end |
.stdlib ⇒ Object
15 16 17 |
# File 'lib/jade/api.rb', line 15 def self.stdlib new(registry: stdlib_registry, source_root: nil, skipped: []) end |
Instance Method Details
#describe(module_name) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jade/api.rb', line 85 def describe(module_name) registry .modules[module_name] &.then do { module: module_name, origin: origin(it), symbols: entries_for(module_name, it), } end end |
#lookup(qualified_name) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/jade/api.rb', line 97 def lookup(qualified_name) *module_parts, name = qualified_name.split('.') module_parts .join('.') .then { describe(it) } &.fetch(:symbols) &.find { it[:name] == name } end |
#modules ⇒ Object
78 79 80 81 82 83 |
# File 'lib/jade/api.rb', line 78 def modules registry .modules .map { |name, entry| { name:, origin: origin(entry) } } .sort_by { [ORIGIN_ORDER.fetch(it[:origin]), it[:name]] } end |
#search(term) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/jade/api.rb', line 106 def search(term) registry .modules .flat_map { |name, entry| entries_for(name, entry) } .select { it[:qualified_name].downcase.include?(term.downcase) } end |