Class: JS2::FS
- Inherits:
-
Object
- Object
- JS2::FS
- Defined in:
- lib/js2/fs.rb
Instance Method Summary collapse
- #dirname(file) ⇒ Object
- #expandPath(file) ⇒ Object
- #find(dir, ext, recursive) ⇒ Object
- #isDirectory(dir) ⇒ Object
- #isFile(dir) ⇒ Object
- #mkdir(dir) ⇒ Object
- #mtime(file) ⇒ Object
- #read(file) ⇒ Object
- #readdir(file) ⇒ Object
- #setInterval(code, time) ⇒ Object
- #write(out, data) ⇒ Object
Instance Method Details
#dirname(file) ⇒ Object
20 21 22 |
# File 'lib/js2/fs.rb', line 20 def dirname(file) return File.dirname(file) end |
#expandPath(file) ⇒ Object
12 13 14 |
# File 'lib/js2/fs.rb', line 12 def (file) return File.(file) end |
#find(dir, ext, recursive) ⇒ Object
7 8 9 10 |
# File 'lib/js2/fs.rb', line 7 def find(dir, ext, recursive) lookup = recursive ? "**" : "." return Dir["#{lookup}/*.#{ext}"].collect { |f| File.(f) }.reject { |f| f.match(/^\./) } end |
#isDirectory(dir) ⇒ Object
16 17 18 |
# File 'lib/js2/fs.rb', line 16 def isDirectory(dir) return File.directory?(dir) end |
#isFile(dir) ⇒ Object
33 34 35 36 |
# File 'lib/js2/fs.rb', line 33 def isFile(dir) return false unless dir return File.file?(dir) end |
#mkdir(dir) ⇒ Object
29 30 31 |
# File 'lib/js2/fs.rb', line 29 def mkdir(dir) FileUtils.mkdir(dir) unless File.exists?(dir) end |
#mtime(file) ⇒ Object
42 43 44 45 46 |
# File 'lib/js2/fs.rb', line 42 def mtime(file) File.stat(file).mtime.to_i rescue return 0 end |
#read(file) ⇒ Object
3 4 5 |
# File 'lib/js2/fs.rb', line 3 def read(file) File.read(file) end |
#readdir(file) ⇒ Object
24 25 26 |
# File 'lib/js2/fs.rb', line 24 def readdir(file) return Dir.entries(file).reject { |f| f.match(/^\.\.?/) } end |
#setInterval(code, time) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/js2/fs.rb', line 48 def setInterval(code, time) while true code.call() sleep(time/1000) end end |
#write(out, data) ⇒ Object
38 39 40 |
# File 'lib/js2/fs.rb', line 38 def write(out, data) File.open(out, 'w') { |f| f << data } end |