Sha256: 6e746becb30353fc36f8f5b148df65016de328ce278369b66344c5651528120d

Contents?: true

Size: 824 Bytes

Versions: 2

Compression:

Stored size: 824 Bytes

Contents

require 'fileutils'

module Canpe
  module FileManipulation

    class NotDirectoryError < StandardError; end

    def create_directory(url)
      puts "create directory: #{url}"
      FileUtils.mkdir_p(url)
    end

    def copy_file(source_url, destination_url)
      puts "copy: #{destination_url}"

      directory = File.dirname(destination_url)

      if File.exists?(directory)
        if File.directory?(directory)
          FileUtils.cp(source_url, destination_url)
        else
          raise NotDirectoryError, "Failed to copy #{destination_url}, because #{directory} is not a directory."
        end
      else
        create_directory(directory)
        FileUtils.cp(source_url, destination_url)
      end
    end

    def remove_file(url)
      puts "delete: #{url}"
      FileUtils.rm(url)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
canpe-0.1.1 lib/canpe/file_manipulation.rb
canpe-0.1.0 lib/canpe/file_manipulation.rb