Class: Rage::OpenAPI::Parsers::Ext::Alba
- Inherits:
-
Object
- Object
- Rage::OpenAPI::Parsers::Ext::Alba
show all
- Defined in:
- lib/rage/openapi/parsers/ext/alba.rb
Defined Under Namespace
Classes: Visitor, VisitorContext
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(namespace: Object) ⇒ Alba
Returns a new instance of Alba.
6
7
8
|
# File 'lib/rage/openapi/parsers/ext/alba.rb', line 6
def initialize(namespace: Object, **)
@namespace = namespace
end
|
Instance Attribute Details
#namespace ⇒ Object
Returns the value of attribute namespace.
4
5
6
|
# File 'lib/rage/openapi/parsers/ext/alba.rb', line 4
def namespace
@namespace
end
|
Instance Method Details
#__parse(klass_str) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/rage/openapi/parsers/ext/alba.rb', line 27
def __parse(klass_str)
is_collection, klass_str = Rage::OpenAPI.__try_parse_collection(klass_str)
klass = @namespace.const_get(klass_str)
source_path, _ = Object.const_source_location(klass.name)
ast = Prism.parse_file(source_path)
visitor = Visitor.new(self, is_collection)
ast.value.accept(visitor)
visitor
end
|
#__parse_nested(klass_str) ⇒ Object
21
22
23
24
25
|
# File 'lib/rage/openapi/parsers/ext/alba.rb', line 21
def __parse_nested(klass_str)
__parse(klass_str).tap { |visitor|
visitor.root_key = visitor.root_key_for_collection = visitor.key_transformer = nil
}.build_schema
end
|
#known_definition?(str) ⇒ Boolean
10
11
12
13
14
15
|
# File 'lib/rage/openapi/parsers/ext/alba.rb', line 10
def known_definition?(str)
_, str = Rage::OpenAPI.__try_parse_collection(str)
defined?(Alba::Resource) && @namespace.const_get(str).ancestors.include?(Alba::Resource)
rescue NameError
false
end
|
#parse(klass_str) ⇒ Object
17
18
19
|
# File 'lib/rage/openapi/parsers/ext/alba.rb', line 17
def parse(klass_str)
__parse(klass_str).build_schema
end
|