Class: GemMirror::MirrorDirectory
- Inherits:
-
Object
- Object
- GemMirror::MirrorDirectory
- Defined in:
- lib/gem_mirror/mirror_directory.rb
Overview
The MirrorDirectory is used for dealing with files and directories that are mirrored from an external source.
Instance Attribute Summary collapse
- #path ⇒ String readonly
Instance Method Summary collapse
-
#add_directory(name) ⇒ GemMirror::MirrorDirectory
Creates a new directory with the given name.
-
#add_file(name, content) ⇒ Gem::MirrorFile
Creates a new file with the given name and content.
-
#file_exists?(name) ⇒ TrueClass|FalseClass
Checks if a given file exists in the current directory.
-
#initialize(path) ⇒ MirrorDirectory
constructor
A new instance of MirrorDirectory.
Constructor Details
#initialize(path) ⇒ MirrorDirectory
Returns a new instance of MirrorDirectory.
17 18 19 |
# File 'lib/gem_mirror/mirror_directory.rb', line 17 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ String (readonly)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gem_mirror/mirror_directory.rb', line 11 class MirrorDirectory attr_reader :path ## # @param [String] path # def initialize(path) @path = path end ## # Creates a new directory with the given name. # # @param [String] name # @return [GemMirror::MirrorDirectory] # def add_directory(name) full_path = File.join(path, name) Dir.mkdir(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 |
Instance Method Details
#add_directory(name) ⇒ GemMirror::MirrorDirectory
Creates a new directory with the given name.
27 28 29 30 31 32 33 |
# File 'lib/gem_mirror/mirror_directory.rb', line 27 def add_directory(name) full_path = File.join(path, name) Dir.mkdir(full_path) unless File.directory?(full_path) self.class.new(full_path) end |
#add_file(name, content) ⇒ Gem::MirrorFile
Creates a new file with the given name and content.
42 43 44 45 46 47 48 49 |
# File 'lib/gem_mirror/mirror_directory.rb', line 42 def add_file(name, content) full_path = File.join(path, name) file = MirrorFile.new(full_path) file.write(content) file end |
#file_exists?(name) ⇒ TrueClass|FalseClass
Checks if a given file exists in the current directory.
57 58 59 |
# File 'lib/gem_mirror/mirror_directory.rb', line 57 def file_exists?(name) File.file?(File.join(path, name)) end |