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

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

Defined Under Namespace

Classes: Annotation

Instance Method Summary collapse

Constructor Details

#initialize(klass, options) ⇒ AnnotationBuilder

Returns a new instance of AnnotationBuilder.



56
57
58
59
# File 'lib/annotate_rb/model_annotator/annotation/annotation_builder.rb', line 56

def initialize(klass, options)
  @model = ModelWrapper.new(klass, options)
  @options = options
end

Instance Method Details

#buildObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/annotate_rb/model_annotator/annotation/annotation_builder.rb', line 61

def build
  if @options.get_state(:current_version).nil?
    migration_version = begin
      ActiveRecord::Migrator.current_version
    rescue
      0
    end

    @options.set_state(:current_version, migration_version)
  end

  version = @options.get_state(:current_version)
  table_name = @model.table_name
  table_comment = @model.connection.try(:table_comment, @model.table_name)
  max_size = @model.max_schema_info_width

  _annotation = Annotation.new(@options,
    version: version, table_name: table_name, table_comment: table_comment,
    max_size: max_size, model: @model).build
end