Class: Bluepine::Resolver
- Inherits:
-
Object
- Object
- Bluepine::Resolver
- Defined in:
- lib/bluepine/resolver.rb
Overview
Responsible for registering and looking up the schemas and endpoints
Constant Summary collapse
- Endpoint =
Bluepine::Endpoint
- Attributes =
Bluepine::Attributes
- SchemaNotFound =
Bluepine::Error.create("Endpoint %s cannot be found")
- EndpointNotFound =
Bluepine::Error.create("Schema %s cannot be found")
Instance Method Summary collapse
- #endpoint(path, options = {}, &block) ⇒ Object
-
#endpoints ⇒ Object
Exposes endpoint registry.
-
#initialize(schemas: [], endpoints: [], schema_registry: nil, endpoint_registry: nil, &block) ⇒ Resolver
constructor
A new instance of Resolver.
- #register(type, name, *args, &block) ⇒ Object
- #resolve(type, name) ⇒ Object
- #schema(name, options = {}, &block) ⇒ Object
-
#schemas ⇒ Object
Exposes schema registry.
Constructor Details
#initialize(schemas: [], endpoints: [], schema_registry: nil, endpoint_registry: nil, &block) ⇒ Resolver
Returns a new instance of Resolver.
41 42 43 44 45 46 47 48 |
# File 'lib/bluepine/resolver.rb', line 41 def initialize(schemas: [], endpoints: [], schema_registry: nil, endpoint_registry: nil, &block) @registries = { schemas: create_schema_registry(schemas, schema_registry), endpoints: create_endpoint_registry(endpoints, endpoint_registry) } instance_exec(&block) if block_given? end |
Instance Method Details
#endpoint(path, options = {}, &block) ⇒ Object
74 75 76 77 78 |
# File 'lib/bluepine/resolver.rb', line 74 def endpoint(path, = {}, &block) return resolve(:endpoints, Endpoint.normalize_name(path)) unless block_given? register(:endpoints, path, , &block) end |
#endpoints ⇒ Object
Exposes endpoint registry
64 65 66 |
# File 'lib/bluepine/resolver.rb', line 64 def endpoints @registries[:endpoints] end |
#register(type, name, *args, &block) ⇒ Object
54 55 56 |
# File 'lib/bluepine/resolver.rb', line 54 def register(type, name, *args, &block) @registries[type].create(name, *args, &block) end |
#resolve(type, name) ⇒ Object
50 51 52 |
# File 'lib/bluepine/resolver.rb', line 50 def resolve(type, name) @registries[type].get(name) end |
#schema(name, options = {}, &block) ⇒ Object
68 69 70 71 72 |
# File 'lib/bluepine/resolver.rb', line 68 def schema(name, = {}, &block) return resolve(:schemas, name) unless block_given? register(:schemas, name, , &block) end |
#schemas ⇒ Object
Exposes schema registry
59 60 61 |
# File 'lib/bluepine/resolver.rb', line 59 def schemas @registries[:schemas] end |