Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/opal-file.rb,
lib/opal-file/stat.rb

Defined Under Namespace

Classes: Stat

Class Method Summary collapse

Class Method Details

.atime(filename) ⇒ Object



20
21
22
# File 'lib/opal-file.rb', line 20

def atime(filename)
  File::Stat.new(filename).atime
end

.birthtime(filename) ⇒ Object



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

def birthtime(filename)
  File::Stat.new(filename).birthtime
end

.chmod(mode, *filename) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/opal-file.rb', line 28

def chmod(mode, *filename)
  handle_errno do
    filename.each do |f|
      fs.JS.chmodSync(f, mode)
    end
  end
end

.chown(owner, group, *filename) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/opal-file.rb', line 36

def chown(owner, group, *filename)
  handle_errno do
    filename.each do |f|
      fs.JS.chownSync(f, owner, group)
    end
  end
end

.directory?(filename) ⇒ Boolean

overwrites Opal corelib/file method

Returns:

  • (Boolean)


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

def directory?(filename)
  FileTest.directory?(filename)
end

.exist?(filename) ⇒ Boolean

overwrites Opal corelib/file method

Returns:

  • (Boolean)


60
61
62
# File 'lib/opal-file.rb', line 60

def exist?(filename)
  FileTest.exist?(filename)
end

.exists?(filename) ⇒ Boolean

overwrites Opal corelib/file method

Returns:

  • (Boolean)


65
66
67
# File 'lib/opal-file.rb', line 65

def exists?(filename)
  FileTest.exists?(filename)
end

.fnmatch?(pattern, path, flags = 0) ⇒ Boolean Also known as: fnmatch

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


69
70
71
# File 'lib/opal-file.rb', line 69

def fnmatch?(pattern, path, flags = 0)
  raise NotImplementedError
end

.ftype(filename) ⇒ Object



75
76
77
# File 'lib/opal-file.rb', line 75

def ftype(filename)
  File.lstat(filename).ftype
end

.lchmod(mode, *filename) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/opal-file.rb', line 79

def lchmod(mode, *filename)
  handle_errno do
    filename.each do |f|
      fs.JS.lchmodSync(f, mode)
    end
  end
end

.lchown(owner, group, *filename) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/opal-file.rb', line 87

def lchown(owner, group, *filename)
  handle_errno do
    filename.each do |f|
      fs.JS.lchownSync(f, owner, group)
    end
  end
end


95
96
97
98
99
# File 'lib/opal-file.rb', line 95

def link(old, new)
  handle_errno do
    fs.JS.linkSync(old, new)
  end
end

.lstat(filename) ⇒ Object



101
102
103
# File 'lib/opal-file.rb', line 101

def lstat(filename)
  File::Stat.from_lstat(filename)
end

.method_missing(name, *args) ⇒ Object



16
17
18
# File 'lib/opal-file.rb', line 16

def method_missing(name, *args)
  FileTest.public_send(name, *args)
end

.mkfifo(file_name, mode = 0666) ⇒ Object

Raises:

  • (NotImplementedError)


105
106
107
# File 'lib/opal-file.rb', line 105

def mkfifo(file_name, mode = 0666)
  raise NotImplementedError
end

.path(filename) ⇒ Object



109
110
111
112
# File 'lib/opal-file.rb', line 109

def path(filename)
  # TODO: fd
  filename
end

.read(filename, options) ⇒ Object

IO



159
160
161
162
163
# File 'lib/opal-file.rb', line 159

def read(filename, options)
  handle_errno do
    fs.JS.readFileSync(filename, { encoding: "utf8" }.to_n)
  end
end


114
115
116
117
118
# File 'lib/opal-file.rb', line 114

def readlink(filename)
  handle_errno do
    fs.JS.readlinkSync(filename)
  end
end

.rename(from, to) ⇒ Object



123
124
125
126
127
# File 'lib/opal-file.rb', line 123

def rename(from, to)
  handle_errno do
    fs.JS.renameSync(from, to)
  end
end

.stat(filename) ⇒ Object



129
130
131
# File 'lib/opal-file.rb', line 129

def stat(filename)
  File::Stat.new(filename)
end


133
134
135
136
137
# File 'lib/opal-file.rb', line 133

def symlink(old, new)
  handle_errno do
    fs.JS.symlinkSync(old, new)
  end
end

.truncate(path, length) ⇒ Object



139
140
141
142
143
# File 'lib/opal-file.rb', line 139

def truncate(path, length)
  handle_errno do
    fs.JS.truncateSync(path, length)
  end
end

.umask(umask = nil) ⇒ Object

Raises:

  • (NotImplementedError)


145
146
147
# File 'lib/opal-file.rb', line 145

def umask(umask = nil)
  raise NotImplementedError
end


44
45
46
47
48
49
50
# File 'lib/opal-file.rb', line 44

def unlink(*filename)
  handle_errno do
    filename.each do |f|
      fs.JS.unlinkSync(f.to_s)
    end
  end
end

.utime(atime, mtime, *filename) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/opal-file.rb', line 149

def utime(atime, mtime, *filename)
  handle_errno do
    filename.each do |f|
      fs.JS.utimesSync(f, atime.to_i, mtime.to_i) # TODO: s ? ms ?
    end
  end
end

.write(filename, content) ⇒ Object



165
166
167
168
169
# File 'lib/opal-file.rb', line 165

def write(filename, content)
  handle_errno do
    fs.JS.writeFileSync(filename, content.to_s)
  end
end