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:, array: false) ⇒ ColumnInfo

Returns a new instance of ColumnInfo.



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

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

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



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

def array
  @array
end

#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



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

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

Instance Method Details

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



28
29
30
31
32
33
34
35
# File 'lib/zod_rails/introspection/column_info.rb', line 28

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

#hashObject



38
39
40
# File 'lib/zod_rails/introspection/column_info.rb', line 38

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