Class: Spwn
- Inherits:
-
Object
- Object
- Spwn
- Defined in:
- lib/spwn.rb,
lib/spwn/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
Class Attribute Summary collapse
-
.dirs ⇒ Object
readonly
Returns the value of attribute dirs.
-
.extensions ⇒ Object
Returns the value of attribute extensions.
-
.files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
- .clean(path) ⇒ Object
-
.dir(*args, &block) ⇒ Object
Spwn.dir( name , options={} ).
-
.file(*args) ⇒ Object
Spwn.file( name , options={} ).
Class Attribute Details
.dirs ⇒ Object (readonly)
Returns the value of attribute dirs.
6 7 8 |
# File 'lib/spwn.rb', line 6 def dirs @dirs end |
.extensions ⇒ Object
Returns the value of attribute extensions.
5 6 7 |
# File 'lib/spwn.rb', line 5 def extensions @extensions end |
.files ⇒ Object (readonly)
Returns the value of attribute files.
6 7 8 |
# File 'lib/spwn.rb', line 6 def files @files end |
Class Method Details
.clean(path) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/spwn.rb', line 50 def self.clean( path ) # commenting out until I make a replacement for the File object # # if path.nil? # #clean all known files you have spawn # @files.each { |file| File.delete(file) } # @dirs.each { |dir| Dir.rmdir(dir) } # else #empty the given directory path = File.(path) #delete all files and directories Dir.glob(File.join(path,'**','*')).reverse_each do |file| if File.file?(file) File.delete(file) elsif File.directory?(file) Dir.rmdir(file) end end # end @files = [] @dirs = [] end |
.dir(*args, &block) ⇒ Object
Spwn.dir( name , options={} )
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spwn.rb', line 34 def self.dir( *args, &block ) = args.last.is_a?(Hash) ? args.last : {} return spawn_multiples( :dir, *args, &block ) unless [:count].nil? name = args.first.is_a?(String) ? args.first : 'dir' path = File.join(Dir.pwd, next_dirname(name)) Dir.mkdir(path) @dirs << new_dir = Dir.new(path) if block_given? origin = Dir.pwd Dir.chdir(new_dir) yield new_dir Dir.chdir(origin) end new_dir end |
.file(*args) ⇒ Object
Spwn.file( name , options={} )
24 25 26 27 28 29 30 31 |
# File 'lib/spwn.rb', line 24 def self.file( *args ) = args.last.is_a?(Hash) ? args.last : {} return spawn_multiples( :file, *args ) unless [:count].nil? name = args.first.is_a?(String) ? args.first : 'file' ext = [:ext] || @extensions.sample @files << new_file = File.new( next_filename(name, ext), 'w') new_file end |