Class: SchemaCommentMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_comment_matcher.rb

Constant Summary collapse

KEY_DELIM =
'_'.freeze

Class Method Summary collapse

Class Method Details

.enrich(columns) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/schema_comment_matcher.rb', line 13

def self.enrich(columns)
  load_cache

  columns.each do |column|
    k = [column[:schema], column[:table], column[:column], column[:type]].join(KEY_DELIM)
    comment = @cache[k]

    if comment.present?
      column[:comment_text] = comment.text
      column[:comment_user_id] = comment.user_id
      column[:comment_id] = comment.id
    end
  end
end

.load_cacheObject



4
5
6
7
8
9
10
11
# File 'lib/schema_comment_matcher.rb', line 4

def self.load_cache
  @cache = {}
  comments = SchemaComment.all
  comments.each do |comment|
    k = [comment.schema, comment.table, comment.column, comment.target_type].join(KEY_DELIM)
    @cache[k] = comment
  end
end