Sha256: 3f00e83573e727a63c783b66e4b90dadcdf366f833a275c7012e68f5384b08d2

Contents?: true

Size: 1.23 KB

Versions: 26

Compression:

Stored size: 1.23 KB

Contents

# -*- coding: utf-8 -*-
module Gemirro
  ##
  # The MirrorDirectory is used for dealing with files and directories that are
  # mirrored from an external source.
  #
  # @!attribute [r] path
  #  @return [String]
  #
  class MirrorDirectory
    attr_reader :path

    ##
    # @param [String] path
    #
    def initialize(path)
      @path = path
    end

    ##
    # Creates directory or directories with the given path.
    #
    # @param [String] dir_path
    # @return [Gemirro::MirrorDirectory]
    #
    def add_directory(dir_path)
      full_path = File.join(@path, dir_path)
      FileUtils.mkdir_p(full_path) unless File.directory?(full_path)

      self.class.new(full_path)
    end

    ##
    # Creates a new file with the given name and content.
    #
    # @param [String] name
    # @param [String] content
    # @return [Gem::MirrorFile]
    #
    def add_file(name, content)
      full_path = File.join(@path, name)
      file      = MirrorFile.new(full_path)

      file.write(content)

      file
    end

    ##
    # Checks if a given file exists in the current directory.
    #
    # @param [String] name
    # @return [TrueClass|FalseClass]
    #
    def file_exists?(name)
      File.file?(File.join(@path, name))
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
gemirro-0.13.5 lib/gemirro/mirror_directory.rb
gemirro-0.13.4 lib/gemirro/mirror_directory.rb
gemirro-0.13.3 lib/gemirro/mirror_directory.rb
gemirro-0.13.2 lib/gemirro/mirror_directory.rb
gemirro-0.13.1 lib/gemirro/mirror_directory.rb
gemirro-0.12.0 lib/gemirro/mirror_directory.rb
gemirro-0.11.0 lib/gemirro/mirror_directory.rb
gemirro-0.10.5 lib/gemirro/mirror_directory.rb
gemirro-0.10.4 lib/gemirro/mirror_directory.rb
gemirro-0.10.3 lib/gemirro/mirror_directory.rb
gemirro-0.10.2 lib/gemirro/mirror_directory.rb
gemirro-0.10.1 lib/gemirro/mirror_directory.rb
gemirro-0.10.0 lib/gemirro/mirror_directory.rb
gemirro-0.9.1 lib/gemirro/mirror_directory.rb
gemirro-0.9.0 lib/gemirro/mirror_directory.rb
gemirro-0.8.1 lib/gemirro/mirror_directory.rb
gemirro-0.8.0 lib/gemirro/mirror_directory.rb
gemirro-0.7.0 lib/gemirro/mirror_directory.rb
gemirro-0.6.0 lib/gemirro/mirror_directory.rb
gemirro-0.5.0 lib/gemirro/mirror_directory.rb