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.



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

def ignore_pattern_to_export_i18n
  @ignore_pattern_to_export_i18n
end

Instance Method Details

#columnsObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/schema_comments/base.rb', line 13

def columns
  result = super
  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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/schema_comments/base.rb', line 48

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



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/schema_comments/base.rb', line 35

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



25
26
27
# File 'lib/schema_comments/base.rb', line 25

def reset_column_comments
  @column_comments_loaded = false
end

#reset_table_commentsObject



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

def reset_table_comments
  @table_comment = nil
end

#table_commentObject



9
10
11
# File 'lib/schema_comments/base.rb', line 9

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