Skip to content
Snippets Groups Projects
Unverified Commit 6b3a96d7 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

batch with media + create

parent f8130a0e
No related branches found
No related tags found
No related merge requests found
......@@ -27,44 +27,18 @@ class Communication::Website::GithubFile < ApplicationRecord
def publish
return unless github.valid?
params = github_params.merge({
commit: github_commit_message
})
if github.publish(params)
add_to_batch(github)
if github.commit_batch(github_commit_message)
update_column :github_path, about.github_path_generated
publish_media
end
end
handle_asynchronously :publish, queue: 'default'
def publish_media
return unless about.respond_to?(:active_storage_blobs)
about.active_storage_blobs.each { |blob| publish_blob(blob) }
end
def publish_blob(blob)
return unless github.valid?
params = github_blob_params(blob).merge({
commit: github_blob_commit_message(blob)
})
github.publish(params)
end
handle_asynchronously :publish_blob, queue: 'default'
def add_to_batch(github)
github.add_to_batch github_params
add_media_to_batch(github)
end
def add_media_to_batch(github)
return unless about.respond_to?(:active_storage_blobs)
about.active_storage_blobs.each { |blob| add_blob_to_batch(github, blob) }
end
def add_blob_to_batch(github, blob)
github.add_to_batch github_blob_params(blob)
end
def github_frontmatter
@github_frontmatter ||= begin
github_content = github.read_file_at(github_path)
......@@ -76,6 +50,15 @@ class Communication::Website::GithubFile < ApplicationRecord
protected
def add_media_to_batch(github)
return unless about.respond_to?(:active_storage_blobs)
about.active_storage_blobs.each { |blob| add_blob_to_batch(github, blob) }
end
def add_blob_to_batch(github, blob)
github.add_to_batch github_blob_params(blob)
end
def remove_from_github
return unless github.valid?
github.remove github_path, github_remove_commit_message
......
......@@ -4,6 +4,7 @@ module WithGithubFiles
included do
has_many :github_files, class_name: "Communication::Website::GithubFile", as: :about, dependent: :destroy
after_save :create_github_files
after_save_commit :publish_github_files
after_touch :publish_github_files
end
......@@ -26,11 +27,20 @@ module WithGithubFiles
protected
def create_github_files
list_of_websites.each do |website|
github_files.find_or_create_by(website: website)
end
end
def publish_github_files
list_of_websites = respond_to?(:websites) ? websites : [website]
list_of_websites.each do |website|
github_file = github_files.where(website: website).first_or_create
github_file = github_files.find_or_create_by(website: website)
github_file.publish
end
end
def list_of_websites
respond_to?(:websites) ? websites : [website]
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment