class PGTrunk::Operations::Enums::Change

@private Definition for the value’s change

Public Class Methods

build(data) click to toggle source
# File lib/pg_trunk/operations/enums/change.rb, line 11
def self.build(data)
  data.is_a?(self) ? data : new(**data)
end

Public Instance Methods

add?() click to toggle source
# File lib/pg_trunk/operations/enums/change.rb, line 30
def add?
  new_name.blank?
end
invert() click to toggle source
# File lib/pg_trunk/operations/enums/change.rb, line 42
def invert
  { name: new_name, new_name: name }
end
opts() click to toggle source
# File lib/pg_trunk/operations/enums/change.rb, line 38
def opts
  to_h.slice(:before, :after).compact
end
rename?() click to toggle source
# File lib/pg_trunk/operations/enums/change.rb, line 26
def rename?
  new_name.present?
end
to_h() click to toggle source
# File lib/pg_trunk/operations/enums/change.rb, line 34
def to_h
  attributes.compact.symbolize_keys
end
to_sql() click to toggle source
# File lib/pg_trunk/operations/enums/change.rb, line 46
def to_sql
  return "RENAME VALUE '#{name}' TO '#{new_name}'" if new_name.present?

  sql = "ADD VALUE IF NOT EXISTS $value$#{name}$value$"
  sql << " BEFORE $value$#{before}$value$" if before.present?
  sql << " AFTER $value$#{after}$value$" if after.present?
  sql
end