Class: AnnotateRb::ModelAnnotator::AnnotationBuilder
- Inherits:
-
Object
- Object
- AnnotateRb::ModelAnnotator::AnnotationBuilder
- Defined in:
- lib/annotate_rb/model_annotator/annotation_builder.rb
Constant Summary collapse
- PREFIX =
Annotate Models plugin use this header
"== Schema Information"- PREFIX_MD =
"## Schema Information"- END_MARK =
"== Schema Information End"- MD_NAMES_OVERHEAD =
6- MD_TYPE_ALLOWANCE =
18
Instance Method Summary collapse
- #build ⇒ Object
- #header ⇒ Object
-
#initialize(klass, options = {}) ⇒ AnnotationBuilder
constructor
A new instance of AnnotationBuilder.
- #schema_footer_text ⇒ Object
- #schema_header_text ⇒ Object
Constructor Details
#initialize(klass, options = {}) ⇒ AnnotationBuilder
Returns a new instance of AnnotationBuilder.
15 16 17 18 19 |
# File 'lib/annotate_rb/model_annotator/annotation_builder.rb', line 15 def initialize(klass, = {}) @model = ModelWrapper.new(klass, ) = @info = "" # TODO: Make array and build string that way end |
Instance Method Details
#build ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/annotate_rb/model_annotator/annotation_builder.rb', line 21 def build @info = "# #{header}\n" @info += schema_header_text max_size = @model.max_schema_info_width if [:format_markdown] @info += format("# %-#{max_size + MD_NAMES_OVERHEAD}.#{max_size + MD_NAMES_OVERHEAD}s | %-#{MD_TYPE_ALLOWANCE}.#{MD_TYPE_ALLOWANCE}s | %s\n", "Name", "Type", "Attributes") @info += "# #{"-" * (max_size + MD_NAMES_OVERHEAD)} | #{"-" * MD_TYPE_ALLOWANCE} | #{"-" * 27}\n" end @info += @model.columns.map do |col| ColumnAnnotation::AnnotationBuilder.new(col, @model, max_size, ).build end.join if [:show_indexes] && @model.table_exists? @info += IndexAnnotation::AnnotationBuilder.new(@model, ).build end if [:show_foreign_keys] && @model.table_exists? @info += ForeignKeyAnnotation::AnnotationBuilder.new(@model, ).build end @info += @info end |
#header ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/annotate_rb/model_annotator/annotation_builder.rb', line 52 def header header = [:format_markdown] ? PREFIX_MD.dup : PREFIX.dup version = begin ActiveRecord::Migrator.current_version rescue 0 end if [:include_version] && version > 0 header += "\n# Schema version: #{version}" end header end |
#schema_footer_text ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/annotate_rb/model_annotator/annotation_builder.rb', line 83 def info = [] if [:format_rdoc] info << "#--" info << "# #{END_MARK}" info << "#++\n" else info << "#\n" end info.join("\n") end |
#schema_header_text ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/annotate_rb/model_annotator/annotation_builder.rb', line 67 def schema_header_text info = [] info << "#" if [:format_markdown] info << "# Table name: `#{@model.table_name}`" info << "#" info << "# ### Columns" else info << "# Table name: #{@model.table_name}" end info << "#\n" # We want the last line break info.join("\n") end |