Class: WhoAmI::TableColumnInfo
- Inherits:
-
Object
- Object
- WhoAmI::TableColumnInfo
- Defined in:
- lib/who_am_i/table_column_info.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #default ⇒ Object
-
#initialize(table_name:, column:) ⇒ TableColumnInfo
constructor
A new instance of TableColumnInfo.
- #name ⇒ Object
- #not_null? ⇒ Boolean
- #primary_key? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(table_name:, column:) ⇒ TableColumnInfo
Returns a new instance of TableColumnInfo.
3 4 5 6 |
# 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 |
Instance Method Details
#attributes ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 ⇒ Object
44 45 46 47 48 |
# File 'lib/who_am_i/table_column_info.rb', line 44 def default if @column.default "default (#{@column.default})" end end |
#name ⇒ Object
8 9 10 |
# File 'lib/who_am_i/table_column_info.rb', line 8 def name @column.name end |
#not_null? ⇒ Boolean
40 41 42 |
# File 'lib/who_am_i/table_column_info.rb', line 40 def not_null? !@column.null end |
#primary_key? ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 |
# 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 |
#type ⇒ Object
12 13 14 |
# File 'lib/who_am_i/table_column_info.rb', line 12 def type @column.type.to_s end |