Class: Legion::API::Router
- Inherits:
-
Object
- Object
- Legion::API::Router
- Defined in:
- lib/legion/api/router.rb
Instance Method Summary collapse
- #clear! ⇒ Object
- #components_for(lex_name) ⇒ Object
- #discovery_extension(lex_name) ⇒ Object
- #extension_names ⇒ Object
- #extension_routes ⇒ Object
- #find_extension_route(lex_name, component_type, component_name, method_name) ⇒ Object
- #infrastructure_routes ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #library_names ⇒ Object
- #library_routes ⇒ Object
- #methods_for(lex_name, component_type, component_name) ⇒ Object
-
#register_extension_route(**opts) ⇒ Object
— Extension tier —.
-
#register_infrastructure(path, method: :get, summary: nil) ⇒ Object
— Infrastructure tier —.
-
#register_library(gem_name, routes_module) ⇒ Object
— Library gem tier —.
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
6 7 8 9 10 |
# File 'lib/legion/api/router.rb', line 6 def initialize @infrastructure_routes = [] @library_routes = {} @extension_routes = {} end |
Instance Method Details
#clear! ⇒ Object
91 92 93 94 95 |
# File 'lib/legion/api/router.rb', line 91 def clear! @infrastructure_routes.clear @library_routes.clear @extension_routes.clear end |
#components_for(lex_name) ⇒ Object
68 69 70 71 72 |
# File 'lib/legion/api/router.rb', line 68 def components_for(lex_name) @extension_routes.values .select { |r| r[:lex_name] == lex_name.to_s } .group_by { |r| r[:component_type] } end |
#discovery_extension(lex_name) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/legion/api/router.rb', line 82 def discovery_extension(lex_name) comps = components_for(lex_name) return nil if comps.empty? comps.transform_values do |routes| routes.map { |r| { name: r[:component_name], method: r[:method_name], definition: r[:definition] } } end end |
#extension_names ⇒ Object
64 65 66 |
# File 'lib/legion/api/router.rb', line 64 def extension_names @extension_routes.values.map { |r| r[:lex_name] }.uniq end |
#extension_routes ⇒ Object
60 61 62 |
# File 'lib/legion/api/router.rb', line 60 def extension_routes @extension_routes.dup end |
#find_extension_route(lex_name, component_type, component_name, method_name) ⇒ Object
55 56 57 58 |
# File 'lib/legion/api/router.rb', line 55 def find_extension_route(lex_name, component_type, component_name, method_name) key = "#{lex_name}/#{component_type}/#{component_name}/#{method_name}" @extension_routes[key] end |
#infrastructure_routes ⇒ Object
18 19 20 |
# File 'lib/legion/api/router.rb', line 18 def infrastructure_routes @infrastructure_routes.dup end |
#library_names ⇒ Object
32 33 34 |
# File 'lib/legion/api/router.rb', line 32 def library_names @library_routes.keys end |
#library_routes ⇒ Object
28 29 30 |
# File 'lib/legion/api/router.rb', line 28 def library_routes @library_routes.dup end |
#methods_for(lex_name, component_type, component_name) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/legion/api/router.rb', line 74 def methods_for(lex_name, component_type, component_name) @extension_routes.values.select do |r| r[:lex_name] == lex_name.to_s && r[:component_type] == component_type.to_s && r[:component_name] == component_name.to_s end end |
#register_extension_route(**opts) ⇒ Object
— Extension tier —
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/legion/api/router.rb', line 38 def register_extension_route(**opts) lex_name = opts[:lex_name] component_type = opts[:component_type] component_name = opts[:component_name] method_name = opts[:method_name] key = "#{lex_name}/#{component_type}/#{component_name}/#{method_name}" @extension_routes[key] = { lex_name: lex_name.to_s, amqp_prefix: opts[:amqp_prefix].to_s, component_type: component_type.to_s, component_name: component_name.to_s, method_name: method_name.to_s, runner_class: opts[:runner_class], definition: opts[:definition] } end |
#register_infrastructure(path, method: :get, summary: nil) ⇒ Object
— Infrastructure tier —
14 15 16 |
# File 'lib/legion/api/router.rb', line 14 def register_infrastructure(path, method: :get, summary: nil) @infrastructure_routes << { path: path, method: method, summary: summary } end |
#register_library(gem_name, routes_module) ⇒ Object
— Library gem tier —
24 25 26 |
# File 'lib/legion/api/router.rb', line 24 def register_library(gem_name, routes_module) @library_routes[gem_name.to_s] = routes_module end |