Sha256: 168091494f4579d8b6e77e9d7265eb6d394c9c108579d100d4f1b94960795878

Contents?: true

Size: 1.18 KB

Versions: 11

Compression:

Stored size: 1.18 KB

Contents

require 'backup/file_item/base'

module Backup
  module FileItem
    class Local < Backup::FileItem::Base
      attr_reader :timeout

      def initialize
        @timeout = 0
      end

      def create_directory_once *directories
        directories.each do |path|
          FileUtils.mkdir_p(path) unless File.directory? path
        end
      end

      def exists? file
        File.exists? file
      end

      def create_file_once file, data
        data = data.read if data.is_a? File or data.is_a? StringIO
        File.open(file, 'wb') do |f|
          f.print(data)
        end unless File.exists?(file)
      end

      def read_file file
        File.open(file, 'rb') do |f|
          f.read
        end if File.exists? file
      end

      def timeout= time
      end

      def dir path, mask = "*"
        r_mask = mask.gsub('.', '\.').gsub('*', '[^\/]')

        Dir["#{path}/#{mask}"].map do |item|
          match = item.match(/^#{path}\/([^\/]+#{r_mask}).*$/)
          match[1] if match
        end.compact.uniq
      end

      def delete_file path
        FileUtils.rm path
      end

      def delete_dir directory
        FileUtils.remove_dir directory
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
encbs-0.2.5.1 lib/backup/file_item/local.rb
encbs-0.2.5 lib/backup/file_item/local.rb
encbs-0.2.4.6 lib/backup/file_item/local.rb
encbs-0.2.4.5 lib/backup/file_item/local.rb
encbs-0.2.4.4 lib/backup/file_item/local.rb
encbs-0.2.4.3 lib/backup/file_item/local.rb
encbs-0.2.4.2 lib/backup/file_item/local.rb
encbs-0.2.4.1 lib/backup/file_item/local.rb
encbs-0.2.4 lib/backup/file_item/local.rb
encbs-0.2.3 lib/backup/file_item/local.rb
encbs-0.2.2 lib/backup/file_item/local.rb