class GithubPages::Deployer
Public Class Methods
new(git, source, destination, message, handler)
click to toggle source
# File lib/ghpages_deploy/deployer.rb, line 9 def initialize(git, source, destination, message, handler) @git = git @source = source @destination = destination @handler = handler @message = message || "Deployed to '#{@destination}'." end
Public Instance Methods
clean_destination(dest)
click to toggle source
remove files that are already cached in the destination directory or have return false when passed to {Handler#precheck_delete?}
# File lib/ghpages_deploy/deployer.rb, line 32 def clean_destination(dest) cached = @git.ls_files(dest) if @handler cached.select! do |file| results = @handler.on_precheck_delete?(file) # a file gets removed if there are no results or any result is false results.empty? || results.inject(&:&) end end @git.remove(*cached) end
deploy()
click to toggle source
# File lib/ghpages_deploy/deployer.rb, line 17 def deploy deploy_site_to(@destination) @git.stage @handler.on_deploy.flatten.uniq if @handler if @git.staged_modifications('.').empty? $stderr.puts 'No changes detected, not commiting.' else @git.commit_and_push @message $stdout.puts "Commit made with message: #{@message}" end end
Private Instance Methods
deploy_site_to(dest)
click to toggle source
@return [Boolean] true if there were changes to the destination
# File lib/ghpages_deploy/deployer.rb, line 49 def deploy_site_to(dest) clean_destination(dest) # create the full path to the destination FileUtils.mkdir_p(dest) unless File.exist?(@source) && File.directory?(@source) fail "#{@source} does not exist or is not a directory." end # recursively copy all files from @source into dest FileUtils.cp_r("#{@source}/.", dest) stage_destination_files(dest) end
stage_destination_files(dest)
click to toggle source
# File lib/ghpages_deploy/deployer.rb, line 65 def stage_destination_files(dest) files = GithubPages.all_nested_files(@source) files.keep_if { |file| File.file?(file) } files.map! do |file| simple = file.sub(%r{^#{@source}/?}, '') File.join(dest, simple) end @git.stage files end