Newer
Older
# == Schema Information
#
# Table name: communication_website_git_files
#
# id :uuid not null, primary key
# about_type :string not null, indexed => [about_id]
# previous_path :string
# previous_sha :string
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid not null, indexed => [about_type]
# website_id :uuid not null, indexed
#
# Indexes
#
# index_communication_website_git_files_on_website_id (website_id)
# index_communication_website_github_files_on_about (about_type,about_id)
#
# Foreign Keys
#
#
class Communication::Website::GitFile < ApplicationRecord
belongs_to :website, class_name: 'Communication::Website'
belongs_to :about, polymorphic: true
# Handle optional before-sync process
object.before_git_sync
git_file = where(website: website, about: object).first_or_create
website.git_repository.add_git_file git_file
end
(
!synchronized_with_git? ||
previous_path.nil? ||
previous_sha.nil?
)
@path ||= about.git_path(website)&.gsub(/\/+/, '/')
if about.respond_to? :template_static
about.template_static
else
"admin/#{about.class.name.underscore.pluralize}/static"
end
def git_sha_for(path)
website.git_repository.git_sha path
end
def previous_git_sha
@previous_git_sha ||= git_sha_for(previous_path)
end
end
# Based on content, with the provider's algorithm (sha1 or sha256)
def computed_sha
@computed_sha ||= website.git_repository.computed_sha to_s
end
previous_git_sha.present? || # The file exists where it was last time
(
previous_path.nil? && # Never saved in the database
git_sha.present? # but it exists in the git repo
)
exists_on_git? && # File exists
previous_path == path && # at the same place
previous_git_sha == previous_sha # with the same content
end
def different_path?
previous_path != path
end
def different_sha?