Sha256: b8766325f5bb1653647d22b14b322efa5e861ab1bf4f1bff4ffcfe04a7e1c7f7

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

module Astrovan
  module Util
    # Create one or more directories on the remote servers. Intermediate directories will be created
    # as required.
    def mkdir(*paths)
      options = paths.last.is_a?(Hash) ? paths.pop : {}
      # flatten, so that arrays of paths can be passed as arguments
      paths = paths.flatten.join(' ')
      # TODO: consider using sudo?
      exec "mkdir -p #{paths} && chmod g+w #{paths}", options
    end

    # Remove files or directories on the remote servers.
    #
    # Options:
    # * +recursive+ - set to true to attempt to recursively remove a directory
    def rm(*paths)
      options = paths.last.is_a?(Hash) ? paths.pop : {}
      # flatten, so that arrays of paths can be passed as arguments
      paths = paths.flatten.join(' ')
      # TODO: consider using sudo?
      rm = 'rm'
      rm << ' -r' if options.delete(:recursive)
      exec "#{rm} #{paths}", options
    end

    # Create a sylink on the remote servers. Any existing symlink will be removed first.
    #
    # Options:
    # * +to+ - the path to the new symlink
    def symlink(*paths)
      options = paths.last.is_a?(Hash) ? paths.pop : {}
      raise ArgumentError, "You must provide a target using the :to option" unless to = options.delete(:to)
      # flatten, so that arrays of paths can be passed as arguments
      paths = paths.flatten.join(' ')
      # TODO: consider using sudo?
      exec "ln -shf #{paths} #{to}", options
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sbfaulkner-astrovan-0.5.7 lib/astrovan/util.rb
sbfaulkner-astrovan-0.5.8 lib/astrovan/util.rb
sbfaulkner-astrovan-0.5.9 lib/astrovan/util.rb
sbfaulkner-astrovan-0.6.0 lib/astrovan/util.rb