Module: Rod::Utils
- Included in:
- AbstractDatabase, Index::Base, Model
- Defined in:
- lib/rod/utils.rb
Instance Method Summary collapse
-
#remove_file(file_name) ⇒ Object
Removes single file.
-
#remove_files(pattern, skip = nil) ⇒ Object
Remove all files matching the
pattern
. -
#remove_files_but(name) ⇒ Object
Removes all files which are similar (i.e. are generated by RubyInline for the same class) to
name
excluding the file with exactly the name given. -
#report_progress(index, count) ⇒ Object
Reports progress of long-running operation.
Instance Method Details
#remove_file(file_name) ⇒ Object
Removes single file.
7 8 9 10 11 12 |
# File 'lib/rod/utils.rb', line 7 def remove_file(file_name) if test(?f,file_name) File.delete(file_name) puts "Removing #{file_name}" if $ROD_DEBUG end end |
#remove_files(pattern, skip = nil) ⇒ Object
Remove all files matching the pattern
. If skip
given, the file with the given name is not deleted.
16 17 18 19 20 |
# File 'lib/rod/utils.rb', line 16 def remove_files(pattern,skip=nil) Dir.glob(pattern).each do |file_name| remove_file(file_name) unless file_name == skip end end |
#remove_files_but(name) ⇒ Object
Removes all files which are similar (i.e. are generated by RubyInline for the same class) to name
excluding the file with exactly the name given.
25 26 27 |
# File 'lib/rod/utils.rb', line 25 def remove_files_but(name) remove_files(name.sub(INLINE_PATTERN_RE,"*"),name) end |
#report_progress(index, count) ⇒ Object
Reports progress of long-running operation. The index
is the current operation’s step of count
steps.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rod/utils.rb', line 32 def report_progress(index,count) step = (count.to_f/50).to_i return if step == 0 if index % step == 0 if index % (5 * step) == 0 print "#{(index / (5 * step) * 10)}%" else print "." end end end |