Class: Ratbug::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/ratbug/column.rb

Constant Summary collapse

VALID_COLUMN_TYPES =
i[
  bigint
  binary
  boolean
  date
  datetime
  decimal
  float
  integer
  json
  primary_key
  string
  text
  time
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name, nullable, comment) ⇒ Column

Returns a new instance of Column.

Parameters:

  • type (Symbol)
  • name (String)
  • nullable (boolean)
  • comment (String | null)


26
27
28
29
30
31
32
33
34
# File 'lib/ratbug/column.rb', line 26

def initialize(type, name, nullable, comment)
  fail "column type #{type} is invalid" unless VALID_COLUMN_TYPES.include?(type)
  fail "column name is required" if name.blank?

  @type = type
  @name = name
  @nullable = nullable
  @comment = comment
end

Instance Attribute Details

#commentObject

enum: Hash<String, Integer>



4
5
6
# File 'lib/ratbug/column.rb', line 4

def comment
  @comment
end

#enumObject

enum: Hash<String, Integer>



4
5
6
# File 'lib/ratbug/column.rb', line 4

def enum
  @enum
end

#nameObject

enum: Hash<String, Integer>



4
5
6
# File 'lib/ratbug/column.rb', line 4

def name
  @name
end

#nullableObject

enum: Hash<String, Integer>



4
5
6
# File 'lib/ratbug/column.rb', line 4

def nullable
  @nullable
end

#typeObject

enum: Hash<String, Integer>



4
5
6
# File 'lib/ratbug/column.rb', line 4

def type
  @type
end

Instance Method Details

#set_enums(enum_hash) ⇒ Object

Parameters:

  • enum_hash (Hash<String, Integer>)


37
38
39
# File 'lib/ratbug/column.rb', line 37

def set_enums(enum_hash)
  @enum = enum_hash
end

#set_nullable(nullable) ⇒ Object



41
42
43
# File 'lib/ratbug/column.rb', line 41

def set_nullable(nullable)
  @nullable = nullable
end