Module: SchemaComments::Base::ClassMethods

Defined in:
lib/schema_comments/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ignore_pattern_to_export_i18nObject

Returns the value of attribute ignore_pattern_to_export_i18n.



37
38
39
# File 'lib/schema_comments/base.rb', line 37

def ignore_pattern_to_export_i18n
  @ignore_pattern_to_export_i18n
end

Instance Method Details

#columns_with_schema_commentsObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/schema_comments/base.rb', line 17

def columns_with_schema_comments
  result = columns_without_schema_comments
  unless @column_comments_loaded
    column_comment_hash = connection.column_comments(table_name)
    result.each do |column|
      column.comment = column_comment_hash[column.name.to_s]
    end
    @column_comments_loaded = true
  end
  result
end

#export_i18n_attributes(connection = ActiveRecord::Base.connection) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/schema_comments/base.rb', line 52

def export_i18n_attributes(connection = ActiveRecord::Base.connection)
  subclasses = ActiveRecord::Base.send(:subclasses).select do |klass|
    (klass != SchemaComments::SchemaComment) and
      klass.respond_to?(:table_exists?) and klass.table_exists?
  end
  subclasses.inject({}) do |d, m|
    attrs = {}
    m.columns.each do |col|
      next if col.name == 'id'
      comment = (col.comment || '').dup
      comment.gsub!(ignore_pattern_to_export_i18n, '') if ignore_pattern_to_export_i18n
      attrs[col.name] = comment
    end
    d[m.name.underscore] = attrs
    d
  end
end

#export_i18n_modelsObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/schema_comments/base.rb', line 39

def export_i18n_models
  subclasses = ActiveRecord::Base.send(:subclasses).select do |klass|
    (klass != SchemaComments::SchemaComment) and
      klass.respond_to?(:table_exists?) and klass.table_exists?
  end
  subclasses.inject({}) do |d, m|
    comment = m.table_comment || ''
    comment.gsub!(ignore_pattern_to_export_i18n, '') if ignore_pattern_to_export_i18n
    d[m.name.underscore] = comment
    d
  end
end

#reset_column_commentsObject



29
30
31
# File 'lib/schema_comments/base.rb', line 29

def reset_column_comments
  @column_comments_loaded = false
end

#reset_table_commentsObject



33
34
35
# File 'lib/schema_comments/base.rb', line 33

def reset_table_comments
  @table_comment = nil
end

#table_commentObject



13
14
15
# File 'lib/schema_comments/base.rb', line 13

def table_comment
  @table_comment ||= connection.table_comment(table_name)
end