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

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

Instance Method Summary collapse

Constructor Details

#initialize(model, options) ⇒ AnnotationBuilder

Returns a new instance of AnnotationBuilder.



7
8
9
10
# File 'lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb', line 7

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

Instance Method Details

#buildObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/annotate_rb/model_annotator/index_annotation/annotation_builder.rb', line 12

def build
  return Components::NilComponent.new if !@options[:show_indexes]

  indexes = @model.retrieve_indexes_from_table
  return Components::NilComponent.new if indexes.empty?

  max_size = indexes.map { |index| index.name.size }.max + 1

  indexes = indexes.sort_by(&:name).map do |index|
    IndexComponent.new(index, max_size)
  end

  _annotation = Annotation.new(indexes)
end