Class: JS2::FS

Inherits:
Object
  • Object
show all
Defined in:
lib/js2/fs.rb

Instance Method Summary collapse

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 expandPath(file)
  return File.expand_path(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.expand_path(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