Module: SchemaComments::ConnectionAdapters::Adapter

Defined in:
lib/schema_comments/connection_adapters.rb

Instance Method Summary collapse

Instance Method Details

#column_comment(table_name, column_name, comment = nil) ⇒ Object

:nodoc:



25
26
27
28
29
30
31
32
# File 'lib/schema_comments/connection_adapters.rb', line 25

def column_comment(table_name, column_name, comment = nil) #:nodoc:
  if comment
    SchemaComment.save_column_comment(table_name, column_name, comment) unless SchemaComments.quiet
    return comment
  else
    SchemaComment.column_comment(table_name, column_name)
  end
end

#column_comments(*args) ⇒ Object

Mass assignment of comments in the form of a hash. Example:

column_comments(:users, {:first_name => "User's given name", :last_name => "Family name"})
column_comments(:tags , {:id => "Tag IDentifier"})

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/schema_comments/connection_adapters.rb', line 37

def column_comments(*args)
  case args.length
  when 1 then
     # こっちはSchemaComments::Base::ClassMethods#columns_with_schema_commentsから呼び出されます。
    return SchemaComment.column_comments(args.first)
  when 2 then
    if args.last.is_a?(Hash)
      # マイグレーションからActiveRecord関係を経由して呼び出されます。
      table_name = args.first.to_s
      args.last.each do |col, comment|
        column_comment(table_name, col, comment) unless SchemaComments.quiet
      end
      return
    end
  end
  raise ArgumentError, "#{self.class}#column_comments accepts (tabel_name) or (tabel_name, hash_col_comment)"
end

#delete_schema_comments(table_name, column_name = nil) ⇒ Object



65
66
67
# File 'lib/schema_comments/connection_adapters.rb', line 65

def delete_schema_comments(table_name, column_name = nil)
  SchemaComment.destroy_of(table_name, column_name) unless SchemaComments.quiet
end

#table_comment(table_name, comment = nil) ⇒ Object

:nodoc:



55
56
57
58
59
60
61
62
63
# File 'lib/schema_comments/connection_adapters.rb', line 55

def table_comment(table_name, comment = nil) #:nodoc:
  if comment
    comment = (comment[:comment] || comment['comment']) if comment.is_a?(Hash)
    SchemaComment.save_table_comment(table_name, comment) unless SchemaComments.quiet
    return comment
  else
    SchemaComment.table_comment(table_name)
  end
end

#update_schema_comments_column_name(table_name, column_name, new_name) ⇒ Object



73
74
75
# File 'lib/schema_comments/connection_adapters.rb', line 73

def update_schema_comments_column_name(table_name, column_name, new_name)
  SchemaComment.update_column_name(table_name, column_name, new_name) unless SchemaComments.quiet
end

#update_schema_comments_table_name(table_name, new_name) ⇒ Object



69
70
71
# File 'lib/schema_comments/connection_adapters.rb', line 69

def update_schema_comments_table_name(table_name, new_name)
  SchemaComment.update_table_name(table_name, new_name) unless SchemaComments.quiet
end