Class: AnnotateRb::ModelAnnotator::Annotation::AnnotationBuilder::Annotation

Inherits:
Components::Base
  • Object
show all
Defined in:
lib/annotate_rb/model_annotator/annotation/annotation_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Components::Base

#to_default, #to_markdown, #to_rdoc, #to_yard

Constructor Details

#initialize(options, **input) ⇒ Annotation

Returns a new instance of Annotation.



10
11
12
13
14
15
16
17
18
19
# File 'lib/annotate_rb/model_annotator/annotation/annotation_builder.rb', line 10

def initialize(options, **input)
  @options = options

  @version = input[:version]
  @table_name = input[:table_name]
  @table_comment = input[:table_comment]
  @max_size = input[:max_size]
  @model = input[:model]
  @database_name = input[:database_name]
end

Instance Attribute Details

#database_nameObject (readonly)

Returns the value of attribute database_name.



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

def database_name
  @database_name
end

#max_sizeObject (readonly)

Returns the value of attribute max_size.



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

def max_size
  @max_size
end

#table_commentObject (readonly)

Returns the value of attribute table_comment.



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

def table_comment
  @table_comment
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



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

def table_name
  @table_name
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#bodyObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/annotate_rb/model_annotator/annotation/annotation_builder.rb', line 21

def body
  [
    MainHeader.new(version, @options[:include_version]),
    SchemaHeader.new(table_name, table_comment, database_name, @options),
    MarkdownHeader.new(max_size),
    *columns,
    IndexAnnotation::AnnotationBuilder.new(@model, @options).build,
    ForeignKeyAnnotation::AnnotationBuilder.new(@model, @options).build,
    CheckConstraintAnnotation::AnnotationBuilder.new(@model, @options).build,
    EnumAnnotation::AnnotationBuilder.new(@model, @options).build,
    SchemaFooter.new
  ]
end

#buildObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/annotate_rb/model_annotator/annotation/annotation_builder.rb', line 35

def build
  components = body.flatten

  if @options[:format_rdoc]
    components.map(&:to_rdoc).compact.join("\n")
  elsif @options[:format_yard]
    components.map(&:to_yard).compact.join("\n")
  elsif @options[:format_markdown]
    components.map(&:to_markdown).compact.join("\n")
  else
    components.map(&:to_default).compact.join("\n")
  end
end