class Dandelion::Deployer

Public Class Methods

new(adapter, options = {}) click to toggle source
# File lib/dandelion/deployer.rb, line 3
def initialize(adapter, options = {})
  @adapter = adapter
  @options = options
end

Public Instance Methods

deploy_changeset!(changeset) click to toggle source
# File lib/dandelion/deployer.rb, line 8
def deploy_changeset!(changeset)
  changeset.each do |change|
    if exclude?(change.path)
      log.debug("Skipping file: #{change.path}")
    else
      deploy_change!(change)
    end
  end
end
deploy_files!(files) click to toggle source
# File lib/dandelion/deployer.rb, line 18
def deploy_files!(files)
  files.each do |path|
    local_path = remote_path = path

    if path.is_a?(Hash)
      local_path, remote_path = path.first
    end

    if File.directory?(local_path)
      paths = expand_paths(local_path, remote_path)
    else
      paths = [[local_path, remote_path]]
    end

    paths.each do |local_path, remote_path|
      deploy_file!(local_path, remote_path)
    end
  end
end

Private Instance Methods

deploy_change!(change) click to toggle source
# File lib/dandelion/deployer.rb, line 45
def deploy_change!(change)
  case change.type
  when :write
    log.debug("Writing file:  #{change.path}")
    @adapter.write(change.path, change.data)
  when :delete
    log.debug("Deleting file: #{change.path}")  
    @adapter.delete(change.path)
  when :symlink
    if @adapter.respond_to?(:symlink)
      log.debug("Creating symlink: #{change.path}")
      @adapter.symlink(change.path, change.data)
    else
      log.debug("Skipped creating symlink:  #{change.path} -> #{change.data}")
    end
  end
end
deploy_file!(local_path, remote_path) click to toggle source
# File lib/dandelion/deployer.rb, line 40
def deploy_file!(local_path, remote_path)
  log.debug("Writing file:  #{local_path} -> #{remote_path}")
  @adapter.write(remote_path, IO.binread(local_path))
end
exclude?(path) click to toggle source
# File lib/dandelion/deployer.rb, line 63
def exclude?(path)
  excluded = @options[:exclude] || []
  excluded.map { |e| path.start_with?(e) }.any?
end
expand_paths(dir, remote_path) click to toggle source
# File lib/dandelion/deployer.rb, line 68
def expand_paths(dir, remote_path)
  paths = Dir.glob(File.join(dir, '**/*')).map do |path|
    trimmed = trim_path(dir, path)
    [path, File.join(remote_path, trimmed)]
  end

  paths.reject do |local_path, remote_path|
    File.directory?(local_path)
  end
end
log() click to toggle source
# File lib/dandelion/deployer.rb, line 83
def log
  Dandelion.logger
end
trim_path(dir, path) click to toggle source
# File lib/dandelion/deployer.rb, line 79
def trim_path(dir, path)
  path[dir.length..-1]
end