Skip to content

Commit

Permalink
feat: add COMMENT support to indexes
Browse files Browse the repository at this point in the history
This reads out any COMMENT added to an INDEX object and adds its after
the last output on its "details" line.
  • Loading branch information
olleolleolle committed Feb 8, 2024
1 parent 5d01c41 commit 30e1901
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module AnnotateModels
using: {
default: 'USING',
markdown: '_using_'
},
comment: {
default: 'COMMENT',
markdown: '_comment_'
}
}.freeze

Expand Down Expand Up @@ -295,12 +299,22 @@ def index_using_info(index, format = :default)
end
end

def index_comment_info(index, format = :default)
value = index.try(:comment).try(:to_s)
if value.blank?
''
else
" #{INDEX_CLAUSES[:comment][format]} #{value}"
end
end

def final_index_string_in_markdown(index)
details = sprintf(
"%s%s%s",
"%s%s%s%s",
index_unique_info(index, :markdown),
index_where_info(index, :markdown),
index_using_info(index, :markdown)
index_using_info(index, :markdown),
index_comment_info(index, :markdown)
).strip
details = " (#{details})" unless details.blank?

Expand All @@ -314,12 +328,13 @@ def final_index_string_in_markdown(index)

def final_index_string(index, max_size)
sprintf(
"# %-#{max_size}.#{max_size}s %s%s%s%s",
"# %-#{max_size}.#{max_size}s %s%s%s%s%s",
index.name,
"(#{index_columns_info(index).join(',')})",
index_unique_info(index),
index_where_info(index),
index_using_info(index)
index_using_info(index),
index_comment_info(index)
).rstrip + "\n"
end

Expand Down

0 comments on commit 30e1901

Please sign in to comment.