annotaterb 4.10.0 → 4.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/VERSION +1 -1
  4. data/lib/annotate_rb/model_annotator/annotation/annotation_builder.rb +84 -0
  5. data/lib/annotate_rb/model_annotator/annotation/main_header.rb +38 -0
  6. data/lib/annotate_rb/model_annotator/annotation/markdown_header.rb +39 -0
  7. data/lib/annotate_rb/model_annotator/annotation/schema_footer.rb +23 -0
  8. data/lib/annotate_rb/model_annotator/annotation/schema_header.rb +65 -0
  9. data/lib/annotate_rb/model_annotator/annotation.rb +13 -0
  10. data/lib/annotate_rb/model_annotator/annotation_decider.rb +2 -2
  11. data/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation.rb +32 -0
  12. data/lib/annotate_rb/model_annotator/check_constraint_annotation/annotation_builder.rb +11 -35
  13. data/lib/annotate_rb/model_annotator/check_constraint_annotation/check_constraint_component.rb +31 -0
  14. data/lib/annotate_rb/model_annotator/check_constraint_annotation.rb +2 -0
  15. data/lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb +1 -83
  16. data/lib/annotate_rb/model_annotator/column_annotation/attributes_builder.rb +2 -0
  17. data/lib/annotate_rb/model_annotator/column_annotation/column_component.rb +94 -0
  18. data/lib/annotate_rb/model_annotator/column_annotation.rb +1 -0
  19. data/lib/annotate_rb/model_annotator/components.rb +63 -0
  20. data/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation.rb +32 -0
  21. data/lib/annotate_rb/model_annotator/foreign_key_annotation/annotation_builder.rb +10 -42
  22. data/lib/annotate_rb/model_annotator/foreign_key_annotation/foreign_key_component.rb +34 -0
  23. data/lib/annotate_rb/model_annotator/foreign_key_annotation/foreign_key_component_builder.rb +56 -0
  24. data/lib/annotate_rb/model_annotator/foreign_key_annotation.rb +3 -0
  25. data/lib/annotate_rb/model_annotator/index_annotation/annotation.rb +32 -0
  26. data/lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb +6 -90
  27. data/lib/annotate_rb/model_annotator/index_annotation/index_component.rb +90 -0
  28. data/lib/annotate_rb/model_annotator/index_annotation.rb +2 -0
  29. data/lib/annotate_rb/model_annotator/project_annotator.rb +1 -1
  30. data/lib/annotate_rb/model_annotator.rb +2 -0
  31. data/lib/annotate_rb/rake_bootstrapper.rb +1 -17
  32. metadata +17 -3
  33. 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