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, #write_proc
Class Method Summary
collapse
Methods inherited from IO
#closed?, #tty?, #write
Class Method Details
.basename(path) ⇒ Object
27
28
29
|
# File 'opal/opal/corelib/file.rb', line 27
def basename(path)
split(path)[-1]
end
|
.directory?(path) ⇒ Boolean
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'opal/opal/corelib/file.rb', line 36
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
23
24
25
|
# File 'opal/opal/corelib/file.rb', line 23
def dirname(path)
split(path)[0..-2]
end
|
.exist?(path) ⇒ Boolean
Also known as:
exists?
31
32
33
|
# File 'opal/opal/corelib/file.rb', line 31
def exist? path
`Opal.modules[#{path}] != null`
end
|
.expand_path(path, basedir = nil) ⇒ Object
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
50
51
52
|
# File 'opal/opal/corelib/file.rb', line 50
def join(*paths)
paths.join(SEPARATOR).gsub(%r{#{SEPARATOR}+}, SEPARATOR)
end
|
.split(path) ⇒ Object
54
55
56
|
# File 'opal/opal/corelib/file.rb', line 54
def split(path)
path.split(SEPARATOR)
end
|