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:



30
31
32
33
34
35
36
37
# File 'lib/schema_comments/connection_adapters.rb', line 30

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)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/schema_comments/connection_adapters.rb', line 42

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



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

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:



60
61
62
63
64
65
66
67
68
# File 'lib/schema_comments/connection_adapters.rb', line 60

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



78
79
80
# File 'lib/schema_comments/connection_adapters.rb', line 78

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



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

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