Skip to content
Snippets Groups Projects
with_git.rb 869 B
Newer Older
Arnaud Levy's avatar
Arnaud Levy committed
module WithGit
  extend ActiveSupport::Concern

  included do
    has_many  :git_files,
              class_name: "Communication::Website::GitFile",
              as: :about,
              dependent: :destroy
  end

  def sync_with_git
    websites.each do |website|
      identifiers.each do |identifier|
Arnaud Levy's avatar
Arnaud Levy committed
        Communication::Website::GitFile.sync website, self, identifier
        git_dependencies(identifier).each do |object|
          Communication::Website::GitFile.sync website, object, identifier
        end
Arnaud Levy's avatar
Arnaud Levy committed
      end
      website.git_repository.sync!
    end
  end
  handle_asynchronously :sync_with_git


  def git_path_static
Arnaud Levy's avatar
Arnaud Levy committed
    ''
  end

  def git_dependencies(identifier)
    []
Arnaud Levy's avatar
Arnaud Levy committed
  end

  # Overridden for multiple files generation
  def identifiers
    [:static]
  end

  # Overridden if websites relation exists
  def websites
    [website]
  end
end