Class: File

Inherits:
IO show all
Defined in:
opal/opal/corelib/file.rb

Constant Summary

Separator =
SEPARATOR = '/'
ALT_SEPARATOR =
nil
PATH_SEPARATOR =
':'

Constants inherited from IO

IO::SEEK_CUR, IO::SEEK_END, IO::SEEK_SET

Instance Attribute Summary

Attributes inherited from IO

#sync, #tty, #write_proc

Class Method Summary collapse

Methods inherited from IO

#closed?, #flush, #tty?, #write

Class Method Details

.basename(path) ⇒ Object



28
29
30
# File 'opal/opal/corelib/file.rb', line 28

def basename(path)
  split(path)[-1]
end

.directory?(path) ⇒ Boolean

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'opal/opal/corelib/file.rb', line 37

def directory?(path)
  files = []
  %x{
    for (var key in Opal.modules) {
      #{files}.push(key)
    }
  }
  path = path.gsub(%r{(^.#{SEPARATOR}+|#{SEPARATOR}+$)})
  file = files.find do |file|
    file =~ /^#{path}/
  end
  file
end

.dirname(path) ⇒ Object



24
25
26
# File 'opal/opal/corelib/file.rb', line 24

def dirname(path)
  split(path)[0..-2]
end

.exist?(path) ⇒ Boolean Also known as: exists?

Returns:



32
33
34
# File 'opal/opal/corelib/file.rb', line 32

def exist? path
  `Opal.modules[#{path}] != null`
end

.expand_path(path, basedir = nil) ⇒ Object Also known as: realpath



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'opal/opal/corelib/file.rb', line 7

def expand_path(path, basedir = nil)
  path = [basedir, path].compact.join(SEPARATOR)
  parts = path.split(SEPARATOR)
  new_parts = []
  parts[0] = Dir.home if parts.first == '~'

  parts.each do |part|
    if part == '..'
      new_parts.pop
    else
      new_parts << part
    end
  end
  new_parts.join(SEPARATOR)
end

.join(*paths) ⇒ Object



51
52
53
# File 'opal/opal/corelib/file.rb', line 51

def join(*paths)
  paths.join(SEPARATOR).gsub(%r{#{SEPARATOR}+}, SEPARATOR)
end

.split(path) ⇒ Object



55
56
57
# File 'opal/opal/corelib/file.rb', line 55

def split(path)
  path.split(SEPARATOR)
end