fedibird-fe/app/models/generator.rb

28 lines
736 B
Ruby
Raw Permalink Normal View History

2023-02-15 08:04:19 +00:00
# == Schema Information
#
# Table name: generators
#
# id :bigint(8) not null, primary key
# uri :string default(""), not null
# type :integer default(:application), not null
# name :string default(""), not null
# website :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Generator < ApplicationRecord
self.inheritance_column = false
enum type: { Application: 0 }, _suffix: :type
validate :validate_uri_unique
has_many :statuses, dependent: :nullify, inverse_of: :generator
private
def validate_uri_unique
error.add(:base, :invalid) if uri.present? && Generator.where(uri: uri).exists?
end
end