Class: AnnotateRb::ModelAnnotator::IndexAnnotation::AnnotationBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb

Constant Summary collapse

INDEX_CLAUSES =
{
  unique: {
    default: "UNIQUE",
    markdown: "_unique_"
  },
  where: {
    default: "WHERE",
    markdown: "_where_"
  },
  using: {
    default: "USING",
    markdown: "_using_"
  }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(model, options) ⇒ AnnotationBuilder

Returns a new instance of AnnotationBuilder.



22
23
24
25
# File 'lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb', line 22

def initialize(model, options)
  @model = model
  @options = options
end

Instance Method Details

#buildObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb', line 27

def build
  index_info = if @options[:format_markdown]
    "#\n# ### Indexes\n#\n"
  else
    "#\n# Indexes\n#\n"
  end

  indexes = @model.retrieve_indexes_from_table
  return "" if indexes.empty?

  max_size = indexes.collect { |index| index.name.size }.max + 1
  indexes.sort_by(&:name).each do |index|
    index_info += if @options[:format_markdown]
      final_index_string_in_markdown(index)
    else
      final_index_string(index, max_size)
    end
  end

  index_info
end