annotaterb 4.10.1 → 4.11.0
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/CHANGELOG.md +26 -0
- data/VERSION +1 -1
- data/lib/annotate_rb/model_annotator/annotation/annotation_builder.rb +84 -0
- data/lib/annotate_rb/model_annotator/annotation/main_header.rb +38 -0
- data/lib/annotate_rb/model_annotator/annotation/markdown_header.rb +39 -0
- data/lib/annotate_rb/model_annotator/annotation/schema_footer.rb +23 -0
- data/lib/annotate_rb/model_annotator/annotation/schema_header.rb +65 -0
- data/lib/annotate_rb/model_annotator/annotation.rb +13 -0
- data/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation.rb +32 -0
- data/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder.rb +11 -35
- data/lib/annotate_rb/model_annotator/check_constraint_annotation/check_constraint_component.rb +31 -0
- data/lib/annotate_rb/model_annotator/check_constraint_annotation.rb +2 -0
- data/lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb +1 -83
- data/lib/annotate_rb/model_annotator/column_annotation/attributes_builder.rb +2 -0
- data/lib/annotate_rb/model_annotator/column_annotation/column_component.rb +94 -0
- data/lib/annotate_rb/model_annotator/column_annotation.rb +1 -0
- data/lib/annotate_rb/model_annotator/components.rb +63 -0
- data/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation.rb +32 -0
- data/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation_builder.rb +10 -42
- data/lib/annotate_rb/model_annotator/foreign_key_annotation/foreign_key_component.rb +34 -0
- data/lib/annotate_rb/model_annotator/foreign_key_annotation/foreign_key_component_builder.rb +56 -0
- data/lib/annotate_rb/model_annotator/foreign_key_annotation.rb +3 -0
- data/lib/annotate_rb/model_annotator/index_annotation/annotation.rb +32 -0
- data/lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb +6 -90
- data/lib/annotate_rb/model_annotator/index_annotation/index_component.rb +90 -0
- data/lib/annotate_rb/model_annotator/index_annotation.rb +2 -0
- data/lib/annotate_rb/model_annotator/model_wrapper.rb +6 -1
- data/lib/annotate_rb/model_annotator/project_annotator.rb +1 -1
- data/lib/annotate_rb/model_annotator.rb +2 -0
- data/lib/annotate_rb/rake_bootstrapper.rb +1 -17
- metadata +18 -4
- data/lib/annotate_rb/model_annotator/annotation_builder.rb +0 -124
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AnnotateRb
|
4
|
-
module ModelAnnotator
|
5
|
-
class AnnotationBuilder
|
6
|
-
# Annotate Models plugin use this header
|
7
|
-
PREFIX = "== Schema Information"
|
8
|
-
PREFIX_MD = "## Schema Information"
|
9
|
-
|
10
|
-
END_MARK = "== Schema Information End"
|
11
|
-
|
12
|
-
MD_NAMES_OVERHEAD = 6
|
13
|
-
MD_TYPE_ALLOWANCE = 18
|
14
|
-
|
15
|
-
def initialize(klass, options)
|
16
|
-
@model = ModelWrapper.new(klass, options)
|
17
|
-
@options = options
|
18
|
-
@info = "" # TODO: Make array and build string that way
|
19
|
-
end
|
20
|
-
|
21
|
-
def build
|
22
|
-
@info = "#{header}\n"
|
23
|
-
@info += schema_header_text
|
24
|
-
|
25
|
-
max_size = @model.max_schema_info_width
|
26
|
-
|
27
|
-
if @options[:format_markdown]
|
28
|
-
@info += format("# %-#{max_size + MD_NAMES_OVERHEAD}.#{max_size + MD_NAMES_OVERHEAD}s | %-#{MD_TYPE_ALLOWANCE}.#{MD_TYPE_ALLOWANCE}s | %s\n",
|
29
|
-
"Name",
|
30
|
-
"Type",
|
31
|
-
"Attributes")
|
32
|
-
@info += "# #{"-" * (max_size + MD_NAMES_OVERHEAD)} | #{"-" * MD_TYPE_ALLOWANCE} | #{"-" * 27}\n"
|
33
|
-
end
|
34
|
-
|
35
|
-
@info += @model.columns.map do |col|
|
36
|
-
ColumnAnnotation::AnnotationBuilder.new(col, @model, max_size, @options).build
|
37
|
-
end.join
|
38
|
-
|
39
|
-
if @options[:show_indexes] && @model.table_exists?
|
40
|
-
@info += IndexAnnotation::AnnotationBuilder.new(@model, @options).build
|
41
|
-
end
|
42
|
-
|
43
|
-
if @options[:show_foreign_keys] && @model.table_exists?
|
44
|
-
@info += ForeignKeyAnnotation::AnnotationBuilder.new(@model, @options).build
|
45
|
-
end
|
46
|
-
|
47
|
-
if @options[:show_check_constraints] && @model.table_exists?
|
48
|
-
@info += CheckConstraintAnnotation::AnnotationBuilder.new(@model, @options).build
|
49
|
-
end
|
50
|
-
|
51
|
-
@info += schema_footer_text
|
52
|
-
|
53
|
-
@info
|
54
|
-
end
|
55
|
-
|
56
|
-
def header
|
57
|
-
header = @options[:format_markdown] ? PREFIX_MD.dup : PREFIX.dup
|
58
|
-
header = "# #{header}"
|
59
|
-
|
60
|
-
if @options.get_state(:current_version).nil?
|
61
|
-
migration_version = begin
|
62
|
-
ActiveRecord::Migrator.current_version
|
63
|
-
rescue
|
64
|
-
0
|
65
|
-
end
|
66
|
-
|
67
|
-
@options.set_state(:current_version, migration_version)
|
68
|
-
end
|
69
|
-
|
70
|
-
version = @options.get_state(:current_version)
|
71
|
-
|
72
|
-
if @options[:include_version] && version > 0
|
73
|
-
header += "\n# Schema version: #{version}"
|
74
|
-
end
|
75
|
-
|
76
|
-
header
|
77
|
-
end
|
78
|
-
|
79
|
-
def schema_header_text
|
80
|
-
info = []
|
81
|
-
info << "#"
|
82
|
-
|
83
|
-
if @options[:format_markdown]
|
84
|
-
info << "# Table name: `#{table_name}`"
|
85
|
-
info << "#"
|
86
|
-
info << "# ### Columns"
|
87
|
-
else
|
88
|
-
info << "# Table name: #{table_name}"
|
89
|
-
end
|
90
|
-
info << "#\n" # We want the last line break
|
91
|
-
|
92
|
-
info.join("\n")
|
93
|
-
end
|
94
|
-
|
95
|
-
def schema_footer_text
|
96
|
-
info = []
|
97
|
-
|
98
|
-
if @options[:format_rdoc]
|
99
|
-
info << "#--"
|
100
|
-
info << "# #{END_MARK}"
|
101
|
-
info << "#++\n"
|
102
|
-
else
|
103
|
-
info << "#\n"
|
104
|
-
end
|
105
|
-
|
106
|
-
info.join("\n")
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def table_name
|
112
|
-
table_name = @model.table_name
|
113
|
-
display_table_comments = @options[:with_comment] && @options[:with_table_comments]
|
114
|
-
|
115
|
-
if display_table_comments && @model.has_table_comments?
|
116
|
-
table_comment = "(#{@model.table_comments.gsub(/\n/, "\\n")})"
|
117
|
-
table_name = "#{table_name}#{table_comment}"
|
118
|
-
end
|
119
|
-
|
120
|
-
table_name
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|