Class: Gemirro::MirrorDirectory
- Inherits:
-
Object
- Object
- Gemirro::MirrorDirectory
- Defined in:
- lib/gemirro/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(dir_path) ⇒ Gemirro::MirrorDirectory
Creates directory or directories with the given path.
-
#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.
15 16 17 |
# File 'lib/gemirro/mirror_directory.rb', line 15 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ String (readonly)
9 10 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 |
# File 'lib/gemirro/mirror_directory.rb', line 9 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 |
Instance Method Details
#add_directory(dir_path) ⇒ Gemirro::MirrorDirectory
Creates directory or directories with the given path.
25 26 27 28 29 30 |
# File 'lib/gemirro/mirror_directory.rb', line 25 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 |
#add_file(name, content) ⇒ Gem::MirrorFile
Creates a new file with the given name and content.
39 40 41 42 43 44 45 46 |
# File 'lib/gemirro/mirror_directory.rb', line 39 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.
54 55 56 |
# File 'lib/gemirro/mirror_directory.rb', line 54 def file_exists?(name) File.file?(File.join(@path, name)) end |