Class: GithubPages::Deployer

Inherits:
Object
  • Object
show all
Defined in:
lib/ghpages_deploy/deployer.rb

Instance Method Summary collapse

Constructor Details

#initialize(git, source, destination, message, handler) ⇒ Deployer

Returns a new instance of Deployer.



9
10
11
12
13
14
15
# 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

Instance Method Details

#clean_destination(dest) ⇒ Object

remove files that are already cached in the destination directory or have return false when passed to Handler#precheck_delete?



32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

#deployObject



17
18
19
20
21
22
23
24
25
26
27
28
# 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