Class: HtmlMockup::Release::Finalizers::Rsync

Inherits:
Base
  • Object
show all
Defined in:
lib/html_mockup/release/finalizers/rsync.rb

Overview

Finalizes the release by uploading your mockup with rsync to a remote server

See Also:

  • for options

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rsync

Returns a new instance of Rsync.

Parameters:

  • Hash

    options The options

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • String (Object)

    :rsync The Rsync command to run (default is “rsync”)

  • String (Object)

    :remote_path The remote path to upload to

  • String (Object)

    :host The remote host to upload to

  • String (Object)

    :username The remote username to upload to

  • Boolean (Object)

    :ask Prompt the user before uploading (default is true)



18
19
20
21
22
23
24
25
26
# File 'lib/html_mockup/release/finalizers/rsync.rb', line 18

def initialize(options = {})
  @options = {
    :rsync => "rsync",
    :remote_path => "",
    :host => "",
    :username  => "",
    :ask => true
  }.update(options)
end

Instance Method Details

#call(release, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/html_mockup/release/finalizers/rsync.rb', line 28

def call(release, options = {})
  options = @options.dup.update(options)

  # Validate options
  validate_options!(release, options)
  
  if !options[:ask] || (prompt("Do you wish to upload to #{options[:host]}? Type y[es]: ")) =~ /\Ay(es)?\Z/
    begin
      `#{@options[:rsync]} --version`
    rescue Errno::ENOENT
      raise RuntimeError, "Could not find rsync in #{@options[:rsync].inspect}"
    end
    
    local_path = release.build_path.to_s
    remote_path = options[:remote_path]
    
    local_path += "/" unless local_path =~ /\/\Z/
    remote_path += "/" unless remote_path =~ /\/\Z/
    
    release.log(self, "Starting upload of #{(release.build_path + "*")} to #{options[:host]}")
  
    command = "#{options[:rsync]} -az #{Shellwords.escape(local_path)} #{Shellwords.escape(options[:username])}@#{Shellwords.escape(options[:host])}:#{Shellwords.escape(remote_path)}"
    
    # Run r.js optimizer
    output = `#{command}`
    
    # Check if r.js succeeded
    unless $?.success?
      raise RuntimeError, "Rsync failed.\noutput:\n #{output}"
    end
  end
end