Module: Dusel::InstanceMethods
- Included in:
- Dir
- Defined in:
- lib/dusel/instance_methods.rb
Instance Method Summary collapse
-
#collapse ⇒ Object
Recursively removes this directory and all it’s children.
-
#dir(name = nil, &block) {|dir| ... } ⇒ Dir
Creates a new directory inside the parent.
-
#file(name = nil, &block) {|file| ... } ⇒ File
Creates a new file.
Instance Method Details
#collapse ⇒ Object
Recursively removes this directory and all it’s children
159 160 161 162 163 |
# File 'lib/dusel/instance_methods.rb', line 159 def collapse @dusel_files.each { |file| File.delete(file.path) } if @dusel_files @dusel_dirs.each { |dir| dir.collapse } if @dusel_dirs Dir.rmdir(self.path()) end |
#dir(name = nil, &block) {|dir| ... } ⇒ Dir
Creates a new directory inside the parent
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dusel/instance_methods.rb', line 55 def dir(name = nil, &block) new_path = named_path_(name) Dir.mkdir new_path new_dir = Dir.new(new_path) @dusel_dirs ||= [] @dusel_dirs << new_dir if block if block.arity < 1 new_dir.instance_eval(&block) new_dir else block.call(new_dir) end else new_dir end end |
#file(name = nil, &block) {|file| ... } ⇒ File
Note:
In case a block of arity == 0 is passed, the block’s value will be written to the file. The file is rewinded afterwards
Creates a new file
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/dusel/instance_methods.rb', line 113 def file(name = nil, &block) new_path = named_path_(name) new_file = File.open(new_path, "w+") @dusel_files ||= [] @dusel_files << new_file if block if block.arity < 1 new_file.write(block.call()) new_file.rewind new_file else block.call(new_file) end else new_file end end |