# File lib/who_am_i/table_column_info.rb, line 29 def primary_key? case @primary_key when Array @primary_key.include?(name) when String @primary_key == name else false end end
class WhoAmI::TableColumnInfo
Public Class Methods
new(table_name:, column:)
click to toggle source
# File lib/who_am_i/table_column_info.rb, line 3 def initialize(table_name:, column:) @column = column @primary_key = ActiveRecord::Base.get_primary_key(@table_name) end
Public Instance Methods
attributes()
click to toggle source
# File lib/who_am_i/table_column_info.rb, line 16 def attributes @attributes ||= begin attrs = [ not_null? && "not null", primary_key? && "primary key", default, ] attrs.select { |attr| attr } end end
default()
click to toggle source
# File lib/who_am_i/table_column_info.rb, line 44 def default if @column.default "default (#{@column.default})" end end
name()
click to toggle source
# File lib/who_am_i/table_column_info.rb, line 8 def name @column.name end
not_null?()
click to toggle source
# File lib/who_am_i/table_column_info.rb, line 40 def not_null? !@column.null end
primary_key?()
click to toggle source
type()
click to toggle source
# File lib/who_am_i/table_column_info.rb, line 12 def type @column.type.to_s end