annotaterb 4.10.1 → 4.11.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnnotateRb
|
4
|
+
module ModelAnnotator
|
5
|
+
# Shared annotation components
|
6
|
+
module Components
|
7
|
+
class Base
|
8
|
+
# Methods default to #to_default, unless overridden by sub class
|
9
|
+
def to_markdown
|
10
|
+
to_default
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_rdoc
|
14
|
+
to_default
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_yard
|
18
|
+
to_default
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_default
|
22
|
+
raise NoMethodError, "Not implemented by class #{self.class}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class NilComponent < Base
|
27
|
+
# Used when we want to return a component, but does not affect annotation generation.
|
28
|
+
# It will get ignored when the consuming object calls Array#compact
|
29
|
+
def to_default
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class LineBreak < Base
|
35
|
+
def to_default
|
36
|
+
""
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class BlankCommentLine < Base
|
41
|
+
def to_default
|
42
|
+
"#"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Header < Base
|
47
|
+
attr_reader :header
|
48
|
+
|
49
|
+
def initialize(header)
|
50
|
+
@header = header
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_default
|
54
|
+
"# #{header}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_markdown
|
58
|
+
"# ### #{header}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnnotateRb
|
4
|
+
module ModelAnnotator
|
5
|
+
module ForeignKeyAnnotation
|
6
|
+
class Annotation
|
7
|
+
HEADER_TEXT = "Foreign Keys"
|
8
|
+
|
9
|
+
def initialize(foreign_keys)
|
10
|
+
@foreign_keys = foreign_keys
|
11
|
+
end
|
12
|
+
|
13
|
+
def body
|
14
|
+
[
|
15
|
+
Components::BlankCommentLine.new,
|
16
|
+
Components::Header.new(HEADER_TEXT),
|
17
|
+
Components::BlankCommentLine.new,
|
18
|
+
*@foreign_keys
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_markdown
|
23
|
+
body.map(&:to_markdown).join("\n")
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_default
|
27
|
+
body.map(&:to_default).join("\n")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -10,58 +10,26 @@ module AnnotateRb
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def build
|
13
|
-
|
14
|
-
|
15
|
-
else
|
16
|
-
"#\n# Foreign Keys\n#\n"
|
17
|
-
end
|
18
|
-
|
19
|
-
return "" unless @model.connection.respond_to?(:supports_foreign_keys?) &&
|
13
|
+
return Components::NilComponent.new if !@options[:show_foreign_keys]
|
14
|
+
return Components::NilComponent.new unless @model.connection.respond_to?(:supports_foreign_keys?) &&
|
20
15
|
@model.connection.supports_foreign_keys? && @model.connection.respond_to?(:foreign_keys)
|
21
16
|
|
22
17
|
foreign_keys = @model.connection.foreign_keys(@model.table_name)
|
23
|
-
return
|
24
|
-
|
25
|
-
format_name = lambda do |fk|
|
26
|
-
return fk.column if fk.name.blank?
|
18
|
+
return Components::NilComponent.new if foreign_keys.empty?
|
27
19
|
|
28
|
-
|
20
|
+
fks = foreign_keys.map do |fk|
|
21
|
+
ForeignKeyComponentBuilder.new(fk, @options)
|
29
22
|
end
|
30
23
|
|
31
|
-
max_size =
|
32
|
-
foreign_keys.sort_by { |fk| [format_name.call(fk), stringify_columns(fk.column)] }.each do |fk|
|
33
|
-
ref_info = if fk.column.is_a?(Array) # Composite foreign key using multiple columns
|
34
|
-
"#{stringify_columns(fk.column)} => #{fk.to_table}#{stringify_columns(fk.primary_key)}"
|
35
|
-
else
|
36
|
-
"#{fk.column} => #{fk.to_table}.#{fk.primary_key}"
|
37
|
-
end
|
24
|
+
max_size = fks.map(&:formatted_name).map(&:size).max + 1
|
38
25
|
|
39
|
-
|
40
|
-
|
41
|
-
constraints_info += "ON UPDATE => #{fk.on_update} " if fk.on_update
|
42
|
-
constraints_info = constraints_info.strip
|
26
|
+
foreign_key_components = fks.sort_by { |fk| [fk.formatted_name, fk.stringified_columns] }.map do |fk|
|
27
|
+
# fk is a ForeignKeyComponentBuilder
|
43
28
|
|
44
|
-
|
45
|
-
format("# * `%s`%s:\n# * **`%s`**\n",
|
46
|
-
format_name.call(fk),
|
47
|
-
constraints_info.blank? ? "" : " (_#{constraints_info}_)",
|
48
|
-
ref_info)
|
49
|
-
else
|
50
|
-
format("# %-#{max_size}.#{max_size}s %s %s",
|
51
|
-
format_name.call(fk),
|
52
|
-
"(#{ref_info})",
|
53
|
-
constraints_info).rstrip + "\n"
|
54
|
-
end
|
29
|
+
ForeignKeyComponent.new(fk.formatted_name, fk.constraints_info, fk.ref_info, max_size)
|
55
30
|
end
|
56
31
|
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
# The fk columns might be composite keys, so format them into a string for the annotation
|
63
|
-
def stringify_columns(columns)
|
64
|
-
columns.is_a?(Array) ? "[#{columns.join(", ")}]" : columns
|
32
|
+
_annotation = Annotation.new(foreign_key_components)
|
65
33
|
end
|
66
34
|
end
|
67
35
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnnotateRb
|
4
|
+
module ModelAnnotator
|
5
|
+
module ForeignKeyAnnotation
|
6
|
+
class ForeignKeyComponent < Components::Base
|
7
|
+
attr_reader :formatted_name, :constraints_info, :ref_info, :max_size
|
8
|
+
|
9
|
+
def initialize(formatted_name, constraints_info, ref_info, max_size)
|
10
|
+
@formatted_name = formatted_name
|
11
|
+
@constraints_info = constraints_info
|
12
|
+
@ref_info = ref_info
|
13
|
+
@max_size = max_size
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_markdown
|
17
|
+
format("# * `%s`%s:\n# * **`%s`**",
|
18
|
+
formatted_name,
|
19
|
+
constraints_info.blank? ? "" : " (_#{constraints_info}_)",
|
20
|
+
ref_info)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_default
|
24
|
+
# standard:disable Lint/FormatParameterMismatch
|
25
|
+
format("# %-#{max_size}.#{max_size}s %s %s",
|
26
|
+
formatted_name,
|
27
|
+
"(#{ref_info})",
|
28
|
+
constraints_info).rstrip
|
29
|
+
# standard:enable Lint/FormatParameterMismatch
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnnotateRb
|
4
|
+
module ModelAnnotator
|
5
|
+
module ForeignKeyAnnotation
|
6
|
+
class ForeignKeyComponentBuilder
|
7
|
+
attr_reader :foreign_key
|
8
|
+
|
9
|
+
def initialize(foreign_key, options)
|
10
|
+
@foreign_key = foreign_key
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def formatted_name
|
15
|
+
@formatted_name ||= if foreign_key.name.blank?
|
16
|
+
foreign_key.column
|
17
|
+
else
|
18
|
+
@options[:show_complete_foreign_keys] ? foreign_key.name : foreign_key.name.gsub(/(?<=^fk_rails_)[0-9a-f]{10}$/, "...")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def stringified_columns
|
23
|
+
@stringified_columns ||= stringify(foreign_key.column)
|
24
|
+
end
|
25
|
+
|
26
|
+
def stringified_primary_key
|
27
|
+
@stringified_primary_key ||= stringify(foreign_key.primary_key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def constraints_info
|
31
|
+
@constraints_info ||= begin
|
32
|
+
constraints_info = ""
|
33
|
+
constraints_info += "ON DELETE => #{foreign_key.on_delete} " if foreign_key.on_delete
|
34
|
+
constraints_info += "ON UPDATE => #{foreign_key.on_update} " if foreign_key.on_update
|
35
|
+
constraints_info.strip
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def ref_info
|
40
|
+
if foreign_key.column.is_a?(Array) # Composite foreign key using multiple columns
|
41
|
+
"#{stringified_columns} => #{foreign_key.to_table}#{stringified_primary_key}"
|
42
|
+
else
|
43
|
+
"#{foreign_key.column} => #{foreign_key.to_table}.#{foreign_key.primary_key}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# The fk columns or primary key might be composite (an Array), so format them into a string for the annotation
|
50
|
+
def stringify(columns)
|
51
|
+
columns.is_a?(Array) ? "[#{columns.join(", ")}]" : columns
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -4,6 +4,9 @@ module AnnotateRb
|
|
4
4
|
module ModelAnnotator
|
5
5
|
module ForeignKeyAnnotation
|
6
6
|
autoload :AnnotationBuilder, "annotate_rb/model_annotator/foreign_key_annotation/annotation_builder"
|
7
|
+
autoload :Annotation, "annotate_rb/model_annotator/foreign_key_annotation/annotation"
|
8
|
+
autoload :ForeignKeyComponent, "annotate_rb/model_annotator/foreign_key_annotation/foreign_key_component"
|
9
|
+
autoload :ForeignKeyComponentBuilder, "annotate_rb/model_annotator/foreign_key_annotation/foreign_key_component_builder"
|
7
10
|
end
|
8
11
|
end
|
9
12
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnnotateRb
|
4
|
+
module ModelAnnotator
|
5
|
+
module IndexAnnotation
|
6
|
+
class Annotation
|
7
|
+
HEADER_TEXT = "Indexes"
|
8
|
+
|
9
|
+
def initialize(indexes)
|
10
|
+
@indexes = indexes
|
11
|
+
end
|
12
|
+
|
13
|
+
def body
|
14
|
+
[
|
15
|
+
Components::BlankCommentLine.new,
|
16
|
+
Components::Header.new(HEADER_TEXT),
|
17
|
+
Components::BlankCommentLine.new,
|
18
|
+
*@indexes
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_markdown
|
23
|
+
body.map(&:to_markdown).join("\n")
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_default
|
27
|
+
body.map(&:to_default).join("\n")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -4,108 +4,24 @@ module AnnotateRb
|
|
4
4
|
module ModelAnnotator
|
5
5
|
module IndexAnnotation
|
6
6
|
class AnnotationBuilder
|
7
|
-
INDEX_CLAUSES = {
|
8
|
-
unique: {
|
9
|
-
default: "UNIQUE",
|
10
|
-
markdown: "_unique_"
|
11
|
-
},
|
12
|
-
where: {
|
13
|
-
default: "WHERE",
|
14
|
-
markdown: "_where_"
|
15
|
-
},
|
16
|
-
using: {
|
17
|
-
default: "USING",
|
18
|
-
markdown: "_using_"
|
19
|
-
}
|
20
|
-
}.freeze
|
21
|
-
|
22
7
|
def initialize(model, options)
|
23
8
|
@model = model
|
24
9
|
@options = options
|
25
10
|
end
|
26
11
|
|
27
12
|
def build
|
28
|
-
|
29
|
-
"#\n# ### Indexes\n#\n"
|
30
|
-
else
|
31
|
-
"#\n# Indexes\n#\n"
|
32
|
-
end
|
13
|
+
return Components::NilComponent.new if !@options[:show_indexes]
|
33
14
|
|
34
15
|
indexes = @model.retrieve_indexes_from_table
|
35
|
-
return
|
16
|
+
return Components::NilComponent.new if indexes.empty?
|
36
17
|
|
37
|
-
max_size = indexes.
|
38
|
-
indexes.sort_by(&:name).each do |index|
|
39
|
-
index_info += if @options[:format_markdown]
|
40
|
-
final_index_string_in_markdown(index)
|
41
|
-
else
|
42
|
-
final_index_string(index, max_size)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
index_info
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def index_using_info(index, format = :default)
|
52
|
-
value = index.try(:using) && index.using.try(:to_sym)
|
53
|
-
if !value.blank? && value != :btree
|
54
|
-
" #{INDEX_CLAUSES[:using][format]} #{value}"
|
55
|
-
else
|
56
|
-
""
|
57
|
-
end
|
58
|
-
end
|
18
|
+
max_size = indexes.map { |index| index.name.size }.max + 1
|
59
19
|
|
60
|
-
|
61
|
-
|
62
|
-
if value.blank?
|
63
|
-
""
|
64
|
-
else
|
65
|
-
" #{INDEX_CLAUSES[:where][format]} #{value}"
|
20
|
+
indexes = indexes.sort_by(&:name).map do |index|
|
21
|
+
IndexComponent.new(index, max_size)
|
66
22
|
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def index_unique_info(index, format = :default)
|
70
|
-
index.unique ? " #{INDEX_CLAUSES[:unique][format]}" : ""
|
71
|
-
end
|
72
23
|
|
73
|
-
|
74
|
-
details = format(
|
75
|
-
"%s%s%s",
|
76
|
-
index_unique_info(index, :markdown),
|
77
|
-
index_where_info(index, :markdown),
|
78
|
-
index_using_info(index, :markdown)
|
79
|
-
).strip
|
80
|
-
details = " (#{details})" unless details.blank?
|
81
|
-
|
82
|
-
format(
|
83
|
-
"# * `%s`%s:\n# * **`%s`**\n",
|
84
|
-
index.name,
|
85
|
-
details,
|
86
|
-
index_columns_info(index).join("`**\n# * **`")
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
def final_index_string(index, max_size)
|
91
|
-
format(
|
92
|
-
"# %-#{max_size}.#{max_size}s %s%s%s%s",
|
93
|
-
index.name,
|
94
|
-
"(#{index_columns_info(index).join(",")})",
|
95
|
-
index_unique_info(index),
|
96
|
-
index_where_info(index),
|
97
|
-
index_using_info(index)
|
98
|
-
).rstrip + "\n"
|
99
|
-
end
|
100
|
-
|
101
|
-
def index_columns_info(index)
|
102
|
-
Array(index.columns).map do |col|
|
103
|
-
if index.try(:orders) && index.orders[col.to_s]
|
104
|
-
"#{col} #{index.orders[col.to_s].upcase}"
|
105
|
-
else
|
106
|
-
col.to_s.gsub("\r", '\r').gsub("\n", '\n')
|
107
|
-
end
|
108
|
-
end
|
24
|
+
_annotation = Annotation.new(indexes)
|
109
25
|
end
|
110
26
|
end
|
111
27
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnnotateRb
|
4
|
+
module ModelAnnotator
|
5
|
+
module IndexAnnotation
|
6
|
+
class IndexComponent < Components::Base
|
7
|
+
attr_reader :index, :max_size
|
8
|
+
|
9
|
+
def initialize(index, max_size)
|
10
|
+
@index = index
|
11
|
+
@max_size = max_size
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_default
|
15
|
+
unique_info = index.unique ? " UNIQUE" : ""
|
16
|
+
|
17
|
+
value = index.try(:where).try(:to_s)
|
18
|
+
where_info = if value.present?
|
19
|
+
" WHERE #{value}"
|
20
|
+
else
|
21
|
+
""
|
22
|
+
end
|
23
|
+
|
24
|
+
value = index.try(:using).try(:to_sym)
|
25
|
+
using_info = if value.present? && value != :btree
|
26
|
+
" USING #{value}"
|
27
|
+
else
|
28
|
+
""
|
29
|
+
end
|
30
|
+
|
31
|
+
# standard:disable Lint/FormatParameterMismatch
|
32
|
+
sprintf(
|
33
|
+
"# %-#{max_size}.#{max_size}s %s%s%s%s",
|
34
|
+
index.name,
|
35
|
+
"(#{columns_info.join(",")})",
|
36
|
+
unique_info,
|
37
|
+
where_info,
|
38
|
+
using_info
|
39
|
+
).rstrip
|
40
|
+
# standard:enable Lint/FormatParameterMismatch
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_markdown
|
44
|
+
unique_info = index.unique ? " _unique_" : ""
|
45
|
+
|
46
|
+
value = index.try(:where).try(:to_s)
|
47
|
+
where_info = if value.present?
|
48
|
+
" _where_ #{value}"
|
49
|
+
else
|
50
|
+
""
|
51
|
+
end
|
52
|
+
|
53
|
+
value = index.try(:using).try(:to_sym)
|
54
|
+
using_info = if value.present? && value != :btree
|
55
|
+
" _using_ #{value}"
|
56
|
+
else
|
57
|
+
""
|
58
|
+
end
|
59
|
+
|
60
|
+
details = sprintf(
|
61
|
+
"%s%s%s",
|
62
|
+
unique_info,
|
63
|
+
where_info,
|
64
|
+
using_info
|
65
|
+
).strip
|
66
|
+
details = " (#{details})" unless details.blank?
|
67
|
+
|
68
|
+
sprintf(
|
69
|
+
"# * `%s`%s:\n# * **`%s`**",
|
70
|
+
index.name,
|
71
|
+
details,
|
72
|
+
columns_info.join("`**\n# * **`")
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def columns_info
|
79
|
+
Array(index.columns).map do |col|
|
80
|
+
if index.try(:orders) && index.orders[col.to_s]
|
81
|
+
"#{col} #{index.orders[col.to_s].upcase}"
|
82
|
+
else
|
83
|
+
col.to_s.gsub("\r", '\r').gsub("\n", '\n')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -4,6 +4,8 @@ module AnnotateRb
|
|
4
4
|
module ModelAnnotator
|
5
5
|
module IndexAnnotation
|
6
6
|
autoload :AnnotationBuilder, "annotate_rb/model_annotator/index_annotation/annotation_builder"
|
7
|
+
autoload :IndexComponent, "annotate_rb/model_annotator/index_annotation/index_component"
|
8
|
+
autoload :Annotation, "annotate_rb/model_annotator/index_annotation/annotation"
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
@@ -128,7 +128,12 @@ module AnnotateRb
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def with_comments?
|
131
|
-
@with_comments
|
131
|
+
return @with_comments if instance_variable_defined?(:@with_comments)
|
132
|
+
|
133
|
+
@with_comments =
|
134
|
+
@options[:with_comment] &&
|
135
|
+
@options[:with_column_comments] &&
|
136
|
+
raw_columns.first.respond_to?(:comment) &&
|
132
137
|
raw_columns.map(&:comment).any? { |comment| !comment.nil? }
|
133
138
|
end
|
134
139
|
|
@@ -39,7 +39,7 @@ module AnnotateRb
|
|
39
39
|
instructions = []
|
40
40
|
|
41
41
|
klass.reset_column_information
|
42
|
-
annotation = AnnotationBuilder.new(klass, @options).build
|
42
|
+
annotation = Annotation::AnnotationBuilder.new(klass, @options).build
|
43
43
|
model_name = klass.name.underscore
|
44
44
|
table_name = klass.table_name
|
45
45
|
|
@@ -28,5 +28,7 @@ module AnnotateRb
|
|
28
28
|
autoload :ZeitwerkClassGetter, "annotate_rb/model_annotator/zeitwerk_class_getter"
|
29
29
|
autoload :CheckConstraintAnnotation, "annotate_rb/model_annotator/check_constraint_annotation"
|
30
30
|
autoload :FileToParserMapper, "annotate_rb/model_annotator/file_to_parser_mapper"
|
31
|
+
autoload :Components, "annotate_rb/model_annotator/components"
|
32
|
+
autoload :Annotation, "annotate_rb/model_annotator/annotation"
|
31
33
|
end
|
32
34
|
end
|
@@ -4,30 +4,14 @@ module AnnotateRb
|
|
4
4
|
class RakeBootstrapper
|
5
5
|
class << self
|
6
6
|
def call(options)
|
7
|
-
begin
|
8
|
-
require "rake/dsl_definition"
|
9
|
-
rescue => e
|
10
|
-
# We might just be on an old version of Rake...
|
11
|
-
warn e.message
|
12
|
-
exit e.status_code
|
13
|
-
end
|
14
|
-
|
15
7
|
require "rake"
|
16
|
-
load "./Rakefile" if File.exist?("./Rakefile")
|
8
|
+
load "./Rakefile" if File.exist?("./Rakefile") && !Rake::Task.task_defined?(:environment)
|
17
9
|
|
18
10
|
begin
|
19
11
|
Rake::Task[:environment].invoke
|
20
12
|
rescue
|
21
13
|
nil
|
22
14
|
end
|
23
|
-
|
24
|
-
unless defined?(Rails)
|
25
|
-
# Not in a Rails project, so time to load up the parts of
|
26
|
-
# ActiveSupport we need.
|
27
|
-
require "active_support"
|
28
|
-
require "active_support/core_ext/class/subclasses"
|
29
|
-
require "active_support/core_ext/string/inflections"
|
30
|
-
end
|
31
15
|
end
|
32
16
|
end
|
33
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: annotaterb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew W. Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Annotates Rails/ActiveRecord Models, routes, fixtures, and others based
|
14
14
|
on the database schema.
|
@@ -40,20 +40,29 @@ files:
|
|
40
40
|
- lib/annotate_rb/model_annotator/annotated_file.rb
|
41
41
|
- lib/annotate_rb/model_annotator/annotated_file/generator.rb
|
42
42
|
- lib/annotate_rb/model_annotator/annotated_file/updater.rb
|
43
|
-
- lib/annotate_rb/model_annotator/
|
43
|
+
- lib/annotate_rb/model_annotator/annotation.rb
|
44
|
+
- lib/annotate_rb/model_annotator/annotation/annotation_builder.rb
|
45
|
+
- lib/annotate_rb/model_annotator/annotation/main_header.rb
|
46
|
+
- lib/annotate_rb/model_annotator/annotation/markdown_header.rb
|
47
|
+
- lib/annotate_rb/model_annotator/annotation/schema_footer.rb
|
48
|
+
- lib/annotate_rb/model_annotator/annotation/schema_header.rb
|
44
49
|
- lib/annotate_rb/model_annotator/annotation_decider.rb
|
45
50
|
- lib/annotate_rb/model_annotator/annotation_diff.rb
|
46
51
|
- lib/annotate_rb/model_annotator/annotation_diff_generator.rb
|
47
52
|
- lib/annotate_rb/model_annotator/annotator.rb
|
48
53
|
- lib/annotate_rb/model_annotator/bad_model_file_error.rb
|
49
54
|
- lib/annotate_rb/model_annotator/check_constraint_annotation.rb
|
55
|
+
- lib/annotate_rb/model_annotator/check_constraint_annotation/annotation.rb
|
50
56
|
- lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder.rb
|
57
|
+
- lib/annotate_rb/model_annotator/check_constraint_annotation/check_constraint_component.rb
|
51
58
|
- lib/annotate_rb/model_annotator/column_annotation.rb
|
52
59
|
- lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb
|
53
60
|
- lib/annotate_rb/model_annotator/column_annotation/attributes_builder.rb
|
61
|
+
- lib/annotate_rb/model_annotator/column_annotation/column_component.rb
|
54
62
|
- lib/annotate_rb/model_annotator/column_annotation/column_wrapper.rb
|
55
63
|
- lib/annotate_rb/model_annotator/column_annotation/default_value_builder.rb
|
56
64
|
- lib/annotate_rb/model_annotator/column_annotation/type_builder.rb
|
65
|
+
- lib/annotate_rb/model_annotator/components.rb
|
57
66
|
- lib/annotate_rb/model_annotator/file_name_resolver.rb
|
58
67
|
- lib/annotate_rb/model_annotator/file_parser.rb
|
59
68
|
- lib/annotate_rb/model_annotator/file_parser/annotation_finder.rb
|
@@ -63,9 +72,14 @@ files:
|
|
63
72
|
- lib/annotate_rb/model_annotator/file_parser/yml_parser.rb
|
64
73
|
- lib/annotate_rb/model_annotator/file_to_parser_mapper.rb
|
65
74
|
- lib/annotate_rb/model_annotator/foreign_key_annotation.rb
|
75
|
+
- lib/annotate_rb/model_annotator/foreign_key_annotation/annotation.rb
|
66
76
|
- lib/annotate_rb/model_annotator/foreign_key_annotation/annotation_builder.rb
|
77
|
+
- lib/annotate_rb/model_annotator/foreign_key_annotation/foreign_key_component.rb
|
78
|
+
- lib/annotate_rb/model_annotator/foreign_key_annotation/foreign_key_component_builder.rb
|
67
79
|
- lib/annotate_rb/model_annotator/index_annotation.rb
|
80
|
+
- lib/annotate_rb/model_annotator/index_annotation/annotation.rb
|
68
81
|
- lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb
|
82
|
+
- lib/annotate_rb/model_annotator/index_annotation/index_component.rb
|
69
83
|
- lib/annotate_rb/model_annotator/model_class_getter.rb
|
70
84
|
- lib/annotate_rb/model_annotator/model_files_getter.rb
|
71
85
|
- lib/annotate_rb/model_annotator/model_wrapper.rb
|
@@ -122,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
136
|
- !ruby/object:Gem::Version
|
123
137
|
version: '0'
|
124
138
|
requirements: []
|
125
|
-
rubygems_version: 3.5.
|
139
|
+
rubygems_version: 3.5.11
|
126
140
|
signing_key:
|
127
141
|
specification_version: 4
|
128
142
|
summary: A gem for generating annotations for Rails projects.
|