Sha256: 9ae62ea67c2a4aedce74468f53204d5e16a99bc098aa44a7350794b8253c7646

Contents?: true

Size: 626 Bytes

Versions: 1

Compression:

Stored size: 626 Bytes

Contents

# frozen_string_literal: true

class Site < ApplicationRecord
  include SoftDelete

  belongs_to :site_node
  belongs_to :user

  validates :url, :name, :site_node_id, presence: true
  validates :url, format: { with: /https?:\/\/[\S]+/ }, uniqueness: true

  after_save :update_cache_version
  after_destroy :update_cache_version
  def update_cache_version
    # 记录节点变更时间,用于清除缓存
    CacheVersion.sites_updated_at = Time.now.to_i
  end

  def favicon_url
    return "" if url.blank?
    domain = URI.parse(url).host.sub("www.", "")
    "https://favicon.ruby-china.com/ip2/#{domain}.ico"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
homeland-site-0.3.0 app/models/site.rb