Class: Utf8mb4rails::Migrator::ColumnInfo
- Inherits:
-
Object
- Object
- Utf8mb4rails::Migrator::ColumnInfo
- Defined in:
- lib/utf8mb4rails/migrator/column_info.rb
Overview
Abstraction for dealing with column information received from the database
Constant Summary collapse
- TEXT_TYPES =
%w(CHAR VARCHAR TINYTEXT TEXT MEDIUMTEXT LONGTEXT).freeze
Instance Attribute Summary collapse
-
#info ⇒ Object
Returns the value of attribute info.
Instance Method Summary collapse
-
#default_value_for_sql ⇒ Object
String : the sql part of the default value of the column definition.
-
#initialize(info) ⇒ ColumnInfo
constructor
Receives a hash with (:type, :default, :max_length, :charset).
-
#new_type_for_sql ⇒ Object
String : the sql part of the new type of the column definition.
-
#text_column? ⇒ Boolean
Bool : True if the column is of a text type.
-
#utf8mb4? ⇒ Boolean
Bool : True if the column is in utf8mb4.
Constructor Details
#initialize(info) ⇒ ColumnInfo
Receives a hash with (:type, :default, :max_length, :charset)
11 12 13 |
# File 'lib/utf8mb4rails/migrator/column_info.rb', line 11 def initialize(info) @info = info end |
Instance Attribute Details
#info ⇒ Object
Returns the value of attribute info.
8 9 10 |
# File 'lib/utf8mb4rails/migrator/column_info.rb', line 8 def info @info end |
Instance Method Details
#default_value_for_sql ⇒ Object
Returns String : the sql part of the default value of the column definition.
27 28 29 30 |
# File 'lib/utf8mb4rails/migrator/column_info.rb', line 27 def default_value_for_sql return nil unless info[:default] "default '#{info[:default]}'" end |
#new_type_for_sql ⇒ Object
Returns String : the sql part of the new type of the column definition.
21 22 23 24 |
# File 'lib/utf8mb4rails/migrator/column_info.rb', line 21 def new_type_for_sql return "#{info[:type]}(#{info[:max_length]})" if info[:type] =~ /CHAR/ info[:type] end |
#text_column? ⇒ Boolean
Returns Bool : True if the column is of a text type.
33 34 35 |
# File 'lib/utf8mb4rails/migrator/column_info.rb', line 33 def text_column? TEXT_TYPES.include?(info[:type]) end |
#utf8mb4? ⇒ Boolean
Returns Bool : True if the column is in utf8mb4.
16 17 18 |
# File 'lib/utf8mb4rails/migrator/column_info.rb', line 16 def utf8mb4? info[:charset] =~ /utf8mb4/ end |