Sha256: 587f84acc0dbfe92b83c2c2d5efd976bfb921b846e54c0835c2b891597f06eab

Contents?: true

Size: 988 Bytes

Versions: 13

Compression:

Stored size: 988 Bytes

Contents

module Picky

  module Backends

    module Helpers

      # Common file helpers.
      #
      module File

        # Creates all necessary directories.
        #
        def create_directory path
          FileUtils.mkdir_p ::File.dirname(path)
        end

        # The backup directory of this file.
        # Equal to the file's dirname plus /backup
        #
        def backup_directory path
          ::File.join ::File.dirname(path), 'backup'
        end

        # Prepares the backup directory for the file.
        #
        def prepare_backup target
          FileUtils.mkdir target unless Dir.exists?(target)
        end

        # The backup filename.
        #
        def backup_file_path_of path
          dir, name = ::File.split path
          ::File.join dir, 'backup', name
        end

        # Extracts the size of the file in Bytes.
        #
        def size_of path
          `ls -l #{path} | awk '{print $5}'`.to_i
        end

      end

    end

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
picky-3.5.4 lib/picky/backends/helpers/file.rb
picky-3.5.3 lib/picky/backends/helpers/file.rb
picky-3.5.2 lib/picky/backends/helpers/file.rb
picky-3.5.1 lib/picky/backends/helpers/file.rb
picky-3.5.0 lib/picky/backends/helpers/file.rb
picky-3.4.3 lib/picky/backends/helpers/file.rb
picky-3.4.2 lib/picky/backends/helpers/file.rb
picky-3.4.1 lib/picky/backends/helpers/file.rb
picky-3.4.0 lib/picky/backends/helpers/file.rb
picky-3.3.3 lib/picky/backends/helpers/file.rb
picky-3.3.2 lib/picky/backends/helpers/file.rb
picky-3.3.1 lib/picky/backends/helpers/file.rb
picky-3.3.0 lib/picky/backends/helpers/file.rb