Class: AnnotateRb::ModelAnnotator::ColumnAnnotation::AnnotationBuilder

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

Constant Summary collapse

BARE_TYPE_ALLOWANCE =
16
MD_TYPE_ALLOWANCE =
18

Instance Method Summary collapse

Constructor Details

#initialize(column, model, max_size, options) ⇒ AnnotationBuilder

Returns a new instance of AnnotationBuilder.



10
11
12
13
14
15
# File 'lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb', line 10

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

Instance Method Details

#buildObject



17
18
19
20
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
# File 'lib/annotate_rb/model_annotator/column_annotation/annotation_builder.rb', line 17

def build
  result = ""

  is_primary_key = is_column_primary_key?(@model, @column.name)

  table_indices = @model.retrieve_indexes_from_table
  column_indices = table_indices.select { |ind| ind.columns.include?(@column.name) }

  column_attributes = AttributesBuilder.new(@column, @options, is_primary_key, column_indices).build
  formatted_column_type = TypeBuilder.new(@column, @options).build

  col_name = if @model.with_comments? && @column.comment
    "#{@column.name}(#{@column.comment.gsub(/\n/, '\\n')})"
  else
    @column.name
  end

  result += if @options[:format_rdoc]
    format_rdoc(col_name, @max_size, formatted_column_type, column_attributes)
  elsif @options[:format_yard]
    format_yard(col_name, @max_size, formatted_column_type, column_attributes)
  elsif @options[:format_markdown]
    format_markdown(col_name, @max_size, formatted_column_type, column_attributes)
  else
    format_default(col_name, @max_size, formatted_column_type, column_attributes)
  end

  result
end