Sha256: 8cd3ef944f6307d872570a1c03527262debc1b8ccfe8b761e112b05580904caa

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'net/scp'

module Astrovan
  module Transfer
    # Create a file on the remote servers, rendering the provided data as specified.
    #
    # Options:
    # * +yaml+ - render the provided data as yaml
    # * +to+ - the path to the new file
    def render(options = {})
      if data = options.delete(:yaml)
        data = data.to_yaml
      end
      put data, options
    end

    # Write to a file on the remote servers.
    #
    # Options:
    # * +to+ - the path to the new file
    def put(data, options = {})
      upload StringIO.new(data), options
    end

    # Upload a file to the remote servers.
    #
    # Options:
    # * +to+ - the path to the new file
    def upload(from, options = {})
      raise ArgumentError, "You must provide a target using the :to option" unless to = options.delete(:to)
      session = session_for(options.delete(:on))
      begin
        session.server_list.each do |server|
          server.session(true).scp.upload(from, to)
        end
        session.loop
      ensure
        session.close if session != self.session
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sbfaulkner-astrovan-0.5.9 lib/astrovan/transfer.rb
sbfaulkner-astrovan-0.6.0 lib/astrovan/transfer.rb