Class: Dir
- Defined in:
- opal/stdlib/nodejs/dir.rb,
opal/stdlib/nodejs/tmpdir.rb
Overview
backtick_javascript: true
Class Method Summary collapse
- .[](glob) ⇒ Object
- .chdir(path) ⇒ Object
- .entries(dirname) ⇒ Object
- .glob(pattern) ⇒ Object
- .home ⇒ Object
- .mkdir(path) ⇒ Object
- .mktmpdir(prefix_suffix = nil, *_rest, **_options) ⇒ Object
- .pwd ⇒ Object (also: getwd)
- .tmpdir ⇒ Object
Class Method Details
.[](glob) ⇒ Object
14 15 16 |
# File 'opal/stdlib/nodejs/dir.rb', line 14 def [](glob) `__glob__.sync(#{glob})` end |
.chdir(path) ⇒ Object
26 27 28 |
# File 'opal/stdlib/nodejs/dir.rb', line 26 def chdir(path) `process.chdir(#{path})` end |
.entries(dirname) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'opal/stdlib/nodejs/dir.rb', line 34 def entries(dirname) %x{ var result = []; var entries = __fs__.readdirSync(#{dirname}); for (var i = 0, ii = entries.length; i < ii; i++) { result.push(entries[i]); } return result; } end |
.glob(pattern) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'opal/stdlib/nodejs/dir.rb', line 45 def glob(pattern) pattern = [pattern] unless pattern.respond_to? :each pattern.flat_map do |subpattern| subpattern = subpattern.to_path if subpattern.respond_to? :to_path subpattern = ::Opal.coerce_to!(subpattern, String, :to_str) `__glob__.sync(subpattern)` end end |
.home ⇒ Object
22 23 24 |
# File 'opal/stdlib/nodejs/dir.rb', line 22 def home `__os__.homedir()` end |
.mkdir(path) ⇒ Object
30 31 32 |
# File 'opal/stdlib/nodejs/dir.rb', line 30 def mkdir(path) `__fs__.mkdirSync(#{path})` end |
.mktmpdir(prefix_suffix = nil, *_rest, **_options) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'opal/stdlib/nodejs/tmpdir.rb', line 2 def self.mktmpdir(prefix_suffix = nil, *_rest, **) if `prefix_suffix.$$is_array` prefix = prefix_suffix.join('') elsif `prefix_suffix.$$is_string` prefix = prefix_suffix else prefix = 'd' end path = `#@__fs__.mkdtempSync(prefix)` if block_given? res = yield path `#@__fs__.rmdirSync(path)` return res end path end |
.pwd ⇒ Object Also known as: getwd
18 19 20 |
# File 'opal/stdlib/nodejs/dir.rb', line 18 def pwd `process.cwd().split(__path__.sep).join(__path__.posix.sep)` end |
.tmpdir ⇒ Object
20 21 22 |
# File 'opal/stdlib/nodejs/tmpdir.rb', line 20 def self.tmpdir `#@__os__.tmpdir()` end |