jbuilder-schema 1.0.3 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -2
- data/Gemfile.lock +61 -70
- data/README.md +164 -138
- data/lib/jbuilder/schema/renderer.rb +37 -55
- data/lib/jbuilder/schema/template.rb +113 -155
- data/lib/jbuilder/schema/version.rb +4 -5
- data/lib/jbuilder/schema.rb +26 -8
- metadata +3 -22
- data/lib/jbuilder/jbuilder.rb +0 -23
- data/lib/jbuilder/schema/builder.rb +0 -79
- data/lib/jbuilder/schema/configuration.rb +0 -29
- data/lib/jbuilder/schema/resolver.rb +0 -39
- data/sig/jbuilder/schema.rbs +0 -4
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "jbuilder/schema/resolver"
|
4
|
-
require "jbuilder/schema/renderer"
|
5
|
-
|
6
|
-
module JbuilderSchema
|
7
|
-
# Class that builds schema object from path
|
8
|
-
class Builder
|
9
|
-
attr_reader :path, :template, :model, :locals, :format, :paths
|
10
|
-
|
11
|
-
def initialize(path, **options)
|
12
|
-
@path = path
|
13
|
-
# TODO: Need this for `required`, make it simpler:
|
14
|
-
@model = options[:model]
|
15
|
-
@locals = options[:locals] || {}
|
16
|
-
@format = options[:format]
|
17
|
-
@paths = options[:paths] || ["app/views"]
|
18
|
-
@template = _render_template(**options)
|
19
|
-
end
|
20
|
-
|
21
|
-
def schema!
|
22
|
-
return {} unless template
|
23
|
-
|
24
|
-
case format
|
25
|
-
when :yaml
|
26
|
-
_yaml_schema
|
27
|
-
when :json
|
28
|
-
_json_schema
|
29
|
-
else
|
30
|
-
_schema
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def _schema
|
37
|
-
template.schema!
|
38
|
-
end
|
39
|
-
|
40
|
-
def _stringified_schema
|
41
|
-
_schema.deep_stringify_keys
|
42
|
-
.deep_transform_values { |v| v.is_a?(Symbol) ? v.to_s : v }
|
43
|
-
.deep_transform_values { |v| v.is_a?(Regexp) ? v.source : v }
|
44
|
-
end
|
45
|
-
|
46
|
-
def _yaml_schema
|
47
|
-
YAML.dump(_stringified_schema).html_safe
|
48
|
-
end
|
49
|
-
|
50
|
-
def _json_schema
|
51
|
-
JSON.dump(_stringified_schema).html_safe
|
52
|
-
end
|
53
|
-
|
54
|
-
def _find_template
|
55
|
-
prefix, controller, action, partial = _resolve_path
|
56
|
-
found = nil
|
57
|
-
paths.each do |path|
|
58
|
-
found = Resolver.new("#{path}/#{prefix}").find_all(action, controller, partial)
|
59
|
-
break if found
|
60
|
-
end
|
61
|
-
found
|
62
|
-
end
|
63
|
-
|
64
|
-
def _resolve_path
|
65
|
-
action = path.split("/").last
|
66
|
-
controller = path.split("/")[-2]
|
67
|
-
prefix = path.delete_suffix("/#{controller}/#{action}")
|
68
|
-
partial = action[0] == "_"
|
69
|
-
|
70
|
-
action.delete_prefix!("_") if action[0] == "_"
|
71
|
-
|
72
|
-
[prefix, controller, action, partial]
|
73
|
-
end
|
74
|
-
|
75
|
-
def _render_template(**options)
|
76
|
-
Renderer.new(**options).render(_find_template)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Configuration
|
4
|
-
module JbuilderSchema
|
5
|
-
class << self
|
6
|
-
def configuration
|
7
|
-
@configuration ||= Configuration.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def reset
|
11
|
-
@configuration = Configuration.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def configure
|
15
|
-
yield(configuration)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Configuration class with defaults
|
20
|
-
class Configuration
|
21
|
-
attr_accessor :components_path, :title_name, :description_name
|
22
|
-
|
23
|
-
def initialize
|
24
|
-
@components_path = "components/schemas"
|
25
|
-
@title_name = "title"
|
26
|
-
@description_name = "description"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "jbuilder/schema/template"
|
4
|
-
|
5
|
-
module JbuilderSchema
|
6
|
-
# Resolver finds and returns Jbuilder template.
|
7
|
-
# It basically inherits from ActionView::FileSystemResolver as it does all the job for us.
|
8
|
-
# We're just building our own template in the end of the search.
|
9
|
-
class Resolver < ::ActionView::FileSystemResolver
|
10
|
-
attr_reader :template
|
11
|
-
|
12
|
-
def find_all(name, prefix = nil, partial = false)
|
13
|
-
_find_all(name, prefix, partial)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def _find_all(name, prefix, partial)
|
19
|
-
path = ActionView::TemplatePath.build(name, prefix, partial)
|
20
|
-
templates_from_path(path).first
|
21
|
-
end
|
22
|
-
|
23
|
-
def templates_from_path(path)
|
24
|
-
return [] if path.name.include?(".")
|
25
|
-
|
26
|
-
# Instead of checking for every possible path, as our other globs would
|
27
|
-
# do, scan the directory for files with the right prefix.
|
28
|
-
paths = template_glob("#{escape_entry(path.to_s)}*")
|
29
|
-
|
30
|
-
paths.map do |p|
|
31
|
-
_source(p)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def _source(template)
|
36
|
-
source_for_template(template)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/sig/jbuilder/schema.rbs
DELETED