Class: ZodRails::Introspection::ColumnInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/zod_rails/introspection/column_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, nullable:, has_default:) ⇒ ColumnInfo

Returns a new instance of ColumnInfo.



8
9
10
11
12
13
14
# File 'lib/zod_rails/introspection/column_info.rb', line 8

def initialize(name:, type:, nullable:, has_default:)
  @name = name
  @type = type
  @nullable = nullable
  @has_default = has_default
  freeze
end

Instance Attribute Details

#has_defaultObject (readonly)

Returns the value of attribute has_default.



6
7
8
# File 'lib/zod_rails/introspection/column_info.rb', line 6

def has_default
  @has_default
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/zod_rails/introspection/column_info.rb', line 6

def name
  @name
end

#nullableObject (readonly)

Returns the value of attribute nullable.



6
7
8
# File 'lib/zod_rails/introspection/column_info.rb', line 6

def nullable
  @nullable
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/zod_rails/introspection/column_info.rb', line 6

def type
  @type
end

Class Method Details

.from_column(column) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/zod_rails/introspection/column_info.rb', line 16

def self.from_column(column)
  new(
    name: column.name,
    type: column.type,
    nullable: column.null,
    has_default: !column.default.nil?
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



25
26
27
28
29
30
31
# File 'lib/zod_rails/introspection/column_info.rb', line 25

def ==(other)
  other.is_a?(self.class) &&
    name == other.name &&
    type == other.type &&
    nullable == other.nullable &&
    has_default == other.has_default
end

#hashObject



34
35
36
# File 'lib/zod_rails/introspection/column_info.rb', line 34

def hash
  [self.class, name, type, nullable, has_default].hash
end