1import __fs__ from 'fs'; 2import __path__ from 'path'; 3import __util__ from 'util'; 4import __glob__ from 'glob'; 5import __os__ from 'os'; 6import __xmlhttprequest__ from 'unxhr'; 7 8Opal.modules["nodejs/base"] = function(Opal) {/* Generated by Opal 1.7.3 */ 9 var $module = Opal.module, $const_set = Opal.const_set, $eqeq = Opal.eqeq, $lambda = Opal.lambda, $send = Opal.send, $a, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil; 10 11 Opal.add_stubs('==,first,shift,write_proc=,read_proc=,tty='); 12 13 (function($base, $parent_nesting) { 14 var self = $module($base, 'NodeJS'); 15 16 var $nesting = [self].concat($parent_nesting); 17 18 return $const_set($nesting[0], 'VERSION', process.version) 19 })($nesting[0], $nesting); 20 Opal.exit = process.exit; 21 $const_set($nesting[0], 'ARGV', process.argv.slice(2)); 22 if ($eqeq($$('ARGV').$first(), "--")) { 23 $$('ARGV').$shift() 24 }; 25 $$('STDOUT')['$write_proc=']($lambda(function $$1(string){ 26 27 if (string == null) string = nil; 28 return process.stdout.write(string);;})); 29 $$('STDERR')['$write_proc=']($lambda(function $$2(string){ 30 31 if (string == null) string = nil; 32 return process.stderr.write(string);;})); 33 $$('STDIN')['$read_proc='](function(_count) { 34 // Ignore count, return as much as we can get 35 var buf = Buffer.alloc(65536), count; 36 try { 37 count = __fs__.readSync(this.fd, buf, 0, 65536, null); 38 } 39 catch (e) { // Windows systems may raise EOF 40 return nil; 41 } 42 if (count == 0) return nil; 43 return buf.toString('utf8', 0, count); 44}); 45 $$('STDIN')['$tty='](true); 46 $$('STDOUT')['$tty='](true); 47 return ($a = [true], $send($$('STDERR'), 'tty=', $a), $a[$a.length - 1]); 48}; 49 50Opal.modules["corelib/file"] = function(Opal) {/* Generated by Opal 1.7.3 */ 51 var $truthy = Opal.truthy, $klass = Opal.klass, $const_set = Opal.const_set, $Opal = Opal.Opal, $regexp = Opal.regexp, $rb_plus = Opal.rb_plus, $def = Opal.def, $Kernel = Opal.Kernel, $eqeq = Opal.eqeq, $rb_lt = Opal.rb_lt, $rb_minus = Opal.rb_minus, $range = Opal.range, $send = Opal.send, $slice = Opal.slice, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; 52 53 Opal.add_stubs('respond_to?,to_path,coerce_to!,pwd,split,sub,+,unshift,join,home,raise,start_with?,absolute_path,==,<,dirname,-,basename,empty?,rindex,[],length,nil?,gsub,find,=~,map,each_with_index,flatten,reject,to_proc,end_with?,expand_path,exist?'); 54 return (function($base, $super, $parent_nesting) { 55 var self = $klass($base, $super, 'File'); 56 57 var $nesting = [self].concat($parent_nesting), windows_root_rx = nil; 58 59 60 $const_set($nesting[0], 'Separator', $const_set($nesting[0], 'SEPARATOR', "/")); 61 $const_set($nesting[0], 'ALT_SEPARATOR', nil); 62 $const_set($nesting[0], 'PATH_SEPARATOR', ":"); 63 $const_set($nesting[0], 'FNM_SYSCASE', 0); 64 windows_root_rx = /^[a-zA-Z]:(?:\\|\/)/; 65 return (function(self, $parent_nesting) { 66 var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); 67 68 69 70 $def(self, '$absolute_path', function $$absolute_path(path, basedir) { 71 var sep = nil, sep_chars = nil, new_parts = nil, $ret_or_1 = nil, path_abs = nil, basedir_abs = nil, parts = nil, leading_sep = nil, abs = nil, new_path = nil; 72 73 74 if (basedir == null) basedir = nil; 75 sep = $$('SEPARATOR'); 76 sep_chars = $sep_chars(); 77 new_parts = []; 78 path = ($truthy(path['$respond_to?']("to_path")) ? (path.$to_path()) : (path)); 79 path = $Opal['$coerce_to!'](path, $$$('String'), "to_str"); 80 basedir = ($truthy(($ret_or_1 = basedir)) ? ($ret_or_1) : ($$$('Dir').$pwd())); 81 path_abs = path.substr(0, sep.length) === sep || windows_root_rx.test(path); 82 basedir_abs = basedir.substr(0, sep.length) === sep || windows_root_rx.test(basedir); 83 if ($truthy(path_abs)) { 84 85 parts = path.$split($regexp(["[", sep_chars, "]"])); 86 leading_sep = windows_root_rx.test(path) ? '' : path.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1"); 87 abs = true; 88 } else { 89 90 parts = $rb_plus(basedir.$split($regexp(["[", sep_chars, "]"])), path.$split($regexp(["[", sep_chars, "]"]))); 91 leading_sep = windows_root_rx.test(basedir) ? '' : basedir.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1"); 92 abs = basedir_abs; 93 }; 94 95 var part; 96 for (var i = 0, ii = parts.length; i < ii; i++) { 97 part = parts[i]; 98 99 if ( 100 (part === nil) || 101 (part === '' && ((new_parts.length === 0) || abs)) || 102 (part === '.' && ((new_parts.length === 0) || abs)) 103 ) { 104 continue; 105 } 106 if (part === '..') { 107 new_parts.pop(); 108 } else { 109 new_parts.push(part); 110 } 111 } 112 113 if (!abs && parts[0] !== '.') { 114 new_parts.$unshift(".") 115 } 116 ; 117 new_path = new_parts.$join(sep); 118 if ($truthy(abs)) { 119 new_path = $rb_plus(leading_sep, new_path) 120 }; 121 return new_path; 122 }, -2); 123 124 $def(self, '$expand_path', function $$expand_path(path, basedir) { 125 var self = this, sep = nil, sep_chars = nil, home = nil, leading_sep = nil, home_path_regexp = nil; 126 127 128 if (basedir == null) basedir = nil; 129 sep = $$('SEPARATOR'); 130 sep_chars = $sep_chars(); 131 if ($truthy(path[0] === '~' || (basedir && basedir[0] === '~'))) { 132 133 home = $$('Dir').$home(); 134 if (!$truthy(home)) { 135 $Kernel.$raise($$$('ArgumentError'), "couldn't find HOME environment -- expanding `~'") 136 }; 137 leading_sep = windows_root_rx.test(home) ? '' : home.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1"); 138 if (!$truthy(home['$start_with?'](leading_sep))) { 139 $Kernel.$raise($$$('ArgumentError'), "non-absolute home") 140 }; 141 home = $rb_plus(home, sep); 142 home_path_regexp = $regexp(["^\\~(?:", sep, "|$)"]); 143 path = path.$sub(home_path_regexp, home); 144 if ($truthy(basedir)) { 145 basedir = basedir.$sub(home_path_regexp, home) 146 }; 147 }; 148 return self.$absolute_path(path, basedir); 149 }, -2); 150 151 // Coerce a given path to a path string using #to_path and #to_str 152 function $coerce_to_path(path) { 153 if ($truthy((path)['$respond_to?']("to_path"))) { 154 path = path.$to_path(); 155 } 156 157 path = $Opal['$coerce_to!'](path, $$$('String'), "to_str"); 158 159 return path; 160 } 161 162 // Return a RegExp compatible char class 163 function $sep_chars() { 164 if ($$('ALT_SEPARATOR') === nil) { 165 return Opal.escape_regexp($$('SEPARATOR')); 166 } else { 167 return Opal.escape_regexp($rb_plus($$('SEPARATOR'), $$('ALT_SEPARATOR'))); 168 } 169 } 170 ; 171 172 $def(self, '$dirname', function $$dirname(path, level) { 173 var self = this, sep_chars = nil; 174 175 176 if (level == null) level = 1; 177 if ($eqeq(level, 0)) { 178 return path 179 }; 180 if ($truthy($rb_lt(level, 0))) { 181 $Kernel.$raise($$$('ArgumentError'), "level can't be negative") 182 }; 183 sep_chars = $sep_chars(); 184 path = $coerce_to_path(path); 185 186 var absolute = path.match(new RegExp("^[" + (sep_chars) + "]")), out; 187 188 path = path.replace(new RegExp("[" + (sep_chars) + "]+$"), ''); // remove trailing separators 189 path = path.replace(new RegExp("[^" + (sep_chars) + "]+$"), ''); // remove trailing basename 190 path = path.replace(new RegExp("[" + (sep_chars) + "]+$"), ''); // remove final trailing separators 191 192 if (path === '') { 193 out = absolute ? '/' : '.'; 194 } 195 else { 196 out = path; 197 } 198 199 if (level == 1) { 200 return out; 201 } 202 else { 203 return self.$dirname(out, $rb_minus(level, 1)) 204 } 205 ; 206 }, -2); 207 208 $def(self, '$basename', function $$basename(name, suffix) { 209 var sep_chars = nil; 210 211 212 if (suffix == null) suffix = nil; 213 sep_chars = $sep_chars(); 214 name = $coerce_to_path(name); 215 216 if (name.length == 0) { 217 return name; 218 } 219 220 if (suffix !== nil) { 221 suffix = $Opal['$coerce_to!'](suffix, $$$('String'), "to_str") 222 } else { 223 suffix = null; 224 } 225 226 name = name.replace(new RegExp("(.)[" + (sep_chars) + "]*$"), '$1'); 227 name = name.replace(new RegExp("^(?:.*[" + (sep_chars) + "])?([^" + (sep_chars) + "]+)$"), '$1'); 228 229 if (suffix === ".*") { 230 name = name.replace(/\.[^\.]+$/, ''); 231 } else if(suffix !== null) { 232 suffix = Opal.escape_regexp(suffix); 233 name = name.replace(new RegExp("" + (suffix) + "$"), ''); 234 } 235 236 return name; 237 ; 238 }, -2); 239 240 $def(self, '$extname', function $$extname(path) { 241 var self = this, filename = nil, last_dot_idx = nil; 242 243 244 path = $coerce_to_path(path); 245 filename = self.$basename(path); 246 if ($truthy(filename['$empty?']())) { 247 return "" 248 }; 249 last_dot_idx = filename['$[]']($range(1, -1, false)).$rindex("."); 250 if (($truthy(last_dot_idx['$nil?']()) || ($eqeq($rb_plus(last_dot_idx, 1), $rb_minus(filename.$length(), 1))))) { 251 return "" 252 } else { 253 return filename['$[]'](Opal.Range.$new($rb_plus(last_dot_idx, 1), -1, false)) 254 }; 255 }); 256 257 $def(self, '$exist?', function $exist$ques$1(path) { 258 259 return Opal.modules[path] != null 260 }); 261 262 $def(self, '$directory?', function $directory$ques$2(path) { 263 var files = nil; 264 265 266 files = []; 267 268 for (var key in Opal.modules) { 269 files.push(key) 270 } 271 ; 272 path = path.$gsub($regexp(["(^.", $$('SEPARATOR'), "+|", $$('SEPARATOR'), "+$)"])); 273 return $send(files, 'find', [], function $$3(f){ 274 275 if (f == null) f = nil; 276 return f['$=~']($regexp(["^", path]));}); 277 }); 278 279 $def(self, '$join', function $$join($a) { 280 var $post_args, paths, result = nil; 281 282 283 $post_args = $slice(arguments); 284 paths = $post_args; 285 if ($truthy(paths['$empty?']())) { 286 return "" 287 }; 288 result = ""; 289 paths = $send(paths.$flatten().$each_with_index(), 'map', [], function $$4(item, index){ 290 291 if (item == null) item = nil; 292 if (index == null) index = nil; 293 if (($eqeq(index, 0) && ($truthy(item['$empty?']())))) { 294 return $$('SEPARATOR') 295 } else if (($eqeq(paths.$length(), $rb_plus(index, 1)) && ($truthy(item['$empty?']())))) { 296 return $$('SEPARATOR') 297 } else { 298 return item 299 };}); 300 paths = $send(paths, 'reject', [], "empty?".$to_proc()); 301 $send(paths, 'each_with_index', [], function $$5(item, index){var next_item = nil; 302 303 304 if (item == null) item = nil; 305 if (index == null) index = nil; 306 next_item = paths['$[]']($rb_plus(index, 1)); 307 if ($truthy(next_item['$nil?']())) { 308 return (result = "" + (result) + (item)) 309 } else { 310 311 if (($truthy(item['$end_with?']($$('SEPARATOR'))) && ($truthy(next_item['$start_with?']($$('SEPARATOR')))))) { 312 item = item.$sub($regexp([$$('SEPARATOR'), "+$"]), "") 313 }; 314 return (result = (($truthy(item['$end_with?']($$('SEPARATOR'))) || ($truthy(next_item['$start_with?']($$('SEPARATOR'))))) ? ("" + (result) + (item)) : ("" + (result) + (item) + ($$('SEPARATOR'))))); 315 };}); 316 return result; 317 }, -1); 318 319 $def(self, '$split', function $$split(path) { 320 321 return path.$split($$('SEPARATOR')) 322 }); 323 $alias(self, "realpath", "expand_path"); 324 return $alias(self, "exists?", "exist?"); 325 })(Opal.get_singleton_class(self), $nesting); 326 })('::', $$$('IO'), $nesting) 327}; 328 329Opal.modules["nodejs/file"] = function(Opal) {/* Generated by Opal 1.7.3 */ 330 var $klass = Opal.klass, $truthy = Opal.truthy, $const_set = Opal.const_set, $defs = Opal.defs, $alias = Opal.alias, $slice = Opal.slice, $send = Opal.send, $neqeq = Opal.neqeq, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $assign_ivar = Opal.assign_ivar, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil, $$$ = Opal.$$$; 331 332 Opal.add_stubs('require,constants,raise,warn,const_get,new,size,delete,respond_to?,path,join,call,map,to_proc,start_with?,first,exist?,realpath,!=,close,to_path,pwd,to_str,include?,match?,sub,attr_reader'); 333 334 self.$require("corelib/file"); 335 336 var warnings = {}, errno_codes = $$('Errno').$constants(); 337 338 function handle_unsupported_feature(message) { 339 switch (Opal.config.unsupported_features_severity) { 340 case 'error': 341 $$('Kernel').$raise($$('NotImplementedError'), message) 342 break; 343 case 'warning': 344 warn(message) 345 break; 346 default: // ignore 347 // noop 348 } 349 } 350 function warn(string) { 351 if (warnings[string]) { 352 return; 353 } 354 warnings[string] = true; 355 self.$warn(string); 356 } 357 function is_utf8(bytes) { 358 var i = 0; 359 while (i < bytes.length) { 360 if ((// ASCII 361 bytes[i] === 0x09 || 362 bytes[i] === 0x0A || 363 bytes[i] === 0x0D || 364 (0x20 <= bytes[i] && bytes[i] <= 0x7E) 365 ) 366 ) { 367 i += 1; 368 continue; 369 } 370 371 if ((// non-overlong 2-byte 372 (0xC2 <= bytes[i] && bytes[i] <= 0xDF) && 373 (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) 374 ) 375 ) { 376 i += 2; 377 continue; 378 } 379 380 if ((// excluding overlongs 381 bytes[i] === 0xE0 && 382 (0xA0 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && 383 (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) 384 ) || 385 (// straight 3-byte 386 ((0xE1 <= bytes[i] && bytes[i] <= 0xEC) || 387 bytes[i] === 0xEE || 388 bytes[i] === 0xEF) && 389 (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && 390 (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) 391 ) || 392 (// excluding surrogates 393 bytes[i] === 0xED && 394 (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x9F) && 395 (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) 396 ) 397 ) { 398 i += 3; 399 continue; 400 } 401 402 if ((// planes 1-3 403 bytes[i] === 0xF0 && 404 (0x90 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && 405 (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && 406 (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) 407 ) || 408 (// planes 4-15 409 (0xF1 <= bytes[i] && bytes[i] <= 0xF3) && 410 (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && 411 (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && 412 (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) 413 ) || 414 (// plane 16 415 bytes[i] === 0xF4 && 416 (0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x8F) && 417 (0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && 418 (0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) 419 ) 420 ) { 421 i += 4; 422 continue; 423 } 424 425 return false; 426 } 427 428 return true; 429 } 430 function executeIOAction(action) { 431 try { 432 return action(); 433 } catch (error) { 434 if (errno_codes.indexOf(error.code) >= 0) { 435 var error_class = $$('Errno').$const_get(error.code) 436 $$('Kernel').$raise((error_class).$new(error.message)) 437 } 438 $$('Kernel').$raise(error) 439 } 440 } 441; 442 (function($base, $super, $parent_nesting) { 443 var self = $klass($base, $super, 'File'); 444 445 var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; 446 if (self.__fs__ == null) self.__fs__ = nil; 447 if (self.__path__ == null) self.__path__ = nil; 448 if (self.__util__ == null) self.__util__ = nil; 449 450 $proto.eof = $proto.binary_flag = $proto.path = $proto.fd = nil; 451 452 self.__fs__ = __fs__; 453 self.__path__ = __path__; 454 self.__util__ = __util__; 455 var __TextEncoder__ = typeof TextEncoder !== 'undefined' ? TextEncoder : __util__.TextEncoder; 456 var __TextDecoder__ = typeof TextDecoder !== 'undefined' ? TextDecoder : __util__.TextDecoder; 457 var __utf8TextDecoder__ = new __TextDecoder__('utf8'); 458 var __textEncoder__ = new __TextEncoder__(); 459 if ($truthy(__path__.sep !== $$('Separator'))) { 460 $const_set($nesting[0], 'ALT_SEPARATOR', __path__.sep) 461 }; 462 $defs(self, '$read', function $$read(path) { 463 464 return executeIOAction(function(){return __fs__.readFileSync(path).toString()}) 465 }); 466 $defs(self, '$write', function $$write(path, data) { 467 468 469 executeIOAction(function(){return __fs__.writeFileSync(path, data)}); 470 return data.$size(); 471 }); 472 $defs(self, '$symlink', function $$symlink(path, new_path) { 473 474 475 executeIOAction(function(){return __fs__.symlinkSync(path, new_path)}); 476 return 0; 477 }); 478 $defs(self, '$delete', function $File_delete$1(path) { 479 480 return executeIOAction(function(){return __fs__.unlinkSync(path)}) 481 }); 482 (function(self, $parent_nesting) { 483 484 return $alias(self, "unlink", "delete") 485 })(Opal.get_singleton_class(self), $nesting); 486 $defs(self, '$exist?', function $File_exist$ques$2(path) { 487 488 489 if ($truthy(path['$respond_to?']("path"))) { 490 path = path.$path() 491 }; 492 return executeIOAction(function(){return __fs__.existsSync(path)}); 493 }); 494 $defs(self, '$realpath', function $$realpath(pathname, dir_string, cache) { 495 var block = $$realpath.$$p || nil, self = this; 496 497 $$realpath.$$p = null; 498 499 ; 500 if (dir_string == null) dir_string = nil; 501 if (cache == null) cache = nil; 502 if ($truthy(dir_string)) { 503 pathname = self.$join(dir_string, pathname) 504 }; 505 if ((block !== nil)) { 506 507 __fs__.realpath(pathname, cache, function(error, realpath){ 508 if (error) Opal.IOError.$new(error.message) 509 else block.$call(realpath) 510 }) 511 512 } else { 513 return executeIOAction(function(){return __fs__.realpathSync(pathname, cache)}) 514 }; 515 }, -2); 516 $defs(self, '$join', function $$join($a) { 517 var $post_args, paths, $b, prefix = nil; 518 519 520 $post_args = $slice(arguments); 521 paths = $post_args; 522 paths = $send(paths, 'map', [], "to_s".$to_proc()); 523 prefix = ($truthy(($b = paths.$first(), ($b === nil || $b == null) ? nil : $b['$start_with?']("//"))) ? ("/") : ("")); 524 return prefix + __path__.posix.join.apply(__path__, paths); 525 }, -1); 526 $defs(self, '$directory?', function $File_directory$ques$3(path) { 527 var self = this, result = nil, realpath = nil; 528 529 530 if (!$truthy(self['$exist?'](path))) { 531 return false 532 }; 533 result = executeIOAction(function(){return !!__fs__.lstatSync(path).isDirectory()}); 534 if (!$truthy(result)) { 535 536 realpath = self.$realpath(path); 537 if ($neqeq(realpath, path)) { 538 result = executeIOAction(function(){return !!__fs__.lstatSync(realpath).isDirectory()}) 539 }; 540 }; 541 return result; 542 }); 543 $defs(self, '$file?', function $File_file$ques$4(path) { 544 var self = this, result = nil, realpath = nil; 545 546 547 if (!$truthy(self['$exist?'](path))) { 548 return false 549 }; 550 result = executeIOAction(function(){return !!__fs__.lstatSync(path).isFile()}); 551 if (!$truthy(result)) { 552 553 realpath = self.$realpath(path); 554 if ($neqeq(realpath, path)) { 555 result = executeIOAction(function(){return !!__fs__.lstatSync(realpath).isFile()}) 556 }; 557 }; 558 return result; 559 }); 560 $defs(self, '$readable?', function $File_readable$ques$5(path) { 561 var self = this; 562 563 564 if (!$truthy(self['$exist?'](path))) { 565 return false 566 }; 567 return "\n" + " try {\n" + " __fs__.accessSync(path, __fs__.R_OK);\n" + " return true;\n" + " } catch (error) {\n" + " return false;\n" + " }\n" + " "; 568 }); 569 $defs(self, '$size', function $$size(path) { 570 571 return executeIOAction(function(){return __fs__.lstatSync(path).size}); 572 }); 573 $defs(self, '$open', function $$open(path, mode) { 574 var $yield = $$open.$$p || nil, self = this, file = nil; 575 576 $$open.$$p = null; 577 578 if (mode == null) mode = "r"; 579 file = self.$new(path, mode); 580 if (($yield !== nil)) { 581 582 return (function() { try { 583 return Opal.yield1($yield, file); 584 } finally { 585 file.$close() 586 }; })(); 587 } else { 588 return file 589 }; 590 }, -2); 591 $defs(self, '$stat', function $$stat(path) { 592 593 594 if ($truthy(path['$respond_to?']("path"))) { 595 path = path.$path() 596 }; 597 return $$$($$('File'), 'Stat').$new(path); 598 }); 599 $defs(self, '$mtime', function $$mtime(path) { 600 601 return executeIOAction(function(){return __fs__.statSync(path).mtime}) 602 }); 603 $defs(self, '$symlink?', function $File_symlink$ques$6(path) { 604 605 return executeIOAction(function(){return __fs__.lstatSync(path).isSymbolicLink()}) 606 }); 607 $defs(self, '$absolute_path', function $$absolute_path(path, basedir) { 608 var $ret_or_1 = nil; 609 610 611 if (basedir == null) basedir = nil; 612 path = ($truthy(path['$respond_to?']("to_path")) ? (path.$to_path()) : (path)); 613 basedir = ($truthy(($ret_or_1 = basedir)) ? ($ret_or_1) : ($$('Dir').$pwd())); 614 return __path__.normalize(__path__.resolve(basedir.$to_str(), path.$to_str())).split(__path__.sep).join(__path__.posix.sep); 615 }, -2); 616 617 $def(self, '$initialize', function $$initialize(path, flags) { 618 var $yield = $$initialize.$$p || nil, self = this, encoding_option_rx = nil, fd = nil; 619 620 $$initialize.$$p = null; 621 622 if (flags == null) flags = "r"; 623 self.binary_flag = flags['$include?']("b"); 624 flags = flags.$delete("b"); 625 encoding_option_rx = /:(.*)/; 626 if ($truthy(encoding_option_rx['$match?'](flags))) { 627 628 handle_unsupported_feature("Encoding option (:encoding) is unsupported by Node.js openSync method and will be removed."); 629 flags = flags.$sub(encoding_option_rx, ""); 630 }; 631 self.path = path; 632 fd = executeIOAction(function(){return __fs__.openSync(path, flags)}); 633 return $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [fd, flags], null); 634 }, -2); 635 self.$attr_reader("path"); 636 637 $def(self, '$sysread', function $$sysread(bytes) { 638 var self = this, res = nil; 639 640 if ($truthy(self.eof)) { 641 return self.$raise($$('EOFError'), "end of file reached") 642 } else { 643 644 if ($truthy(self.binary_flag)) { 645 646 647 var buf = executeIOAction(function(){return __fs__.readFileSync(self.path)}) 648 var content 649 if (is_utf8(buf)) { 650 content = buf.toString('utf8') 651 } else { 652 // coerce to utf8 653 content = __utf8TextDecoder__.decode(__textEncoder__.encode(buf.toString('binary'))) 654 } 655 ; 656 res = content; 657 } else { 658 res = executeIOAction(function(){return __fs__.readFileSync(self.path).toString('utf8')}) 659 }; 660 self.eof = true; 661 self.lineno = res.$size(); 662 return res; 663 } 664 }); 665 666 $def(self, '$write', function $$write(string) { 667 var self = this; 668 669 return executeIOAction(function(){return __fs__.writeSync(self.fd, string)}) 670 }); 671 672 $def(self, '$flush', function $$flush() { 673 var self = this; 674 675 return executeIOAction(function(){return __fs__.fsyncSync(self.fd)}) 676 }); 677 678 $def(self, '$close', function $$close() { 679 var $yield = $$close.$$p || nil, self = this; 680 681 $$close.$$p = null; 682 683 executeIOAction(function(){return __fs__.closeSync(self.fd)}); 684 return $send2(self, $find_super(self, 'close', $$close, false, true), 'close', [], $yield); 685 }); 686 return $def(self, '$mtime', function $$mtime() { 687 var self = this; 688 689 return executeIOAction(function(){return __fs__.statSync(self.path).mtime}) 690 }); 691 })($nesting[0], $$('IO'), $nesting); 692 return (function($base, $super) { 693 var self = $klass($base, $super, 'Stat'); 694 695 var $proto = self.$$prototype; 696 if (self.__fs__ == null) self.__fs__ = nil; 697 698 $proto.path = nil; 699 700 self.__fs__ = __fs__; 701 702 $def(self, '$initialize', $assign_ivar("path")); 703 704 $def(self, '$file?', function $Stat_file$ques$7() { 705 var self = this; 706 707 return executeIOAction(function(){return __fs__.statSync(self.path).isFile()}) 708 }); 709 710 $def(self, '$directory?', function $Stat_directory$ques$8() { 711 var self = this; 712 713 return executeIOAction(function(){return __fs__.statSync(self.path).isDirectory()}) 714 }); 715 716 $def(self, '$mtime', function $$mtime() { 717 var self = this; 718 719 return executeIOAction(function(){return __fs__.statSync(self.path).mtime}) 720 }); 721 722 $def(self, '$readable?', function $Stat_readable$ques$9() { 723 var self = this; 724 725 return executeIOAction(function(){return __fs__.accessSync(self.path, __fs__.constants.R_OK)}) 726 }); 727 728 $def(self, '$writable?', function $Stat_writable$ques$10() { 729 var self = this; 730 731 return executeIOAction(function(){return __fs__.accessSync(self.path, __fs__.constants.W_OK)}) 732 }); 733 return $def(self, '$executable?', function $Stat_executable$ques$11() { 734 var self = this; 735 736 return executeIOAction(function(){return __fs__.accessSync(self.path, __fs__.constants.X_OK)}) 737 }); 738 })($$('File'), null); 739}; 740 741Opal.modules["nodejs/dir"] = function(Opal) {/* Generated by Opal 1.7.3 */ 742 var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $send = Opal.send, $Opal = Opal.Opal, $alias = Opal.alias, $nesting = [], nil = Opal.nil; 743 744 Opal.add_stubs('respond_to?,flat_map,to_path,coerce_to!,pwd'); 745 return (function($base, $super, $parent_nesting) { 746 var self = $klass($base, $super, 'Dir'); 747 748 var $nesting = [self].concat($parent_nesting); 749 if (self.__glob__ == null) self.__glob__ = nil; 750 if (self.__fs__ == null) self.__fs__ = nil; 751 if (self.__path__ == null) self.__path__ = nil; 752 if (self.__os__ == null) self.__os__ = nil; 753 754 755 self.__glob__ = __glob__; 756 self.__fs__ = __fs__; 757 self.__path__ = __path__; 758 self.__os__ = __os__; 759 return (function(self, $parent_nesting) { 760 var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); 761 762 763 764 $def(self, '$[]', function $$$1(glob) { 765 766 return __glob__.sync(glob) 767 }); 768 769 $def(self, '$pwd', function $$pwd() { 770 771 return process.cwd().split(__path__.sep).join(__path__.posix.sep); 772 }); 773 774 $def(self, '$home', function $$home() { 775 776 return __os__.homedir(); 777 }); 778 779 $def(self, '$chdir', function $$chdir(path) { 780 781 return process.chdir(path) 782 }); 783 784 $def(self, '$mkdir', function $$mkdir(path) { 785 786 return __fs__.mkdirSync(path) 787 }); 788 789 $def(self, '$entries', function $$entries(dirname) { 790 791 792 var result = []; 793 var entries = __fs__.readdirSync(dirname); 794 for (var i = 0, ii = entries.length; i < ii; i++) { 795 result.push(entries[i]); 796 } 797 return result; 798 799 }); 800 801 $def(self, '$glob', function $$glob(pattern) { 802 803 804 if (!$truthy(pattern['$respond_to?']("each"))) { 805 pattern = [pattern] 806 }; 807 return $send(pattern, 'flat_map', [], function $$2(subpattern){ 808 809 if (subpattern == null) subpattern = nil; 810 if ($truthy(subpattern['$respond_to?']("to_path"))) { 811 subpattern = subpattern.$to_path() 812 }; 813 subpattern = $Opal['$coerce_to!'](subpattern, $$('String'), "to_str"); 814 return __glob__.sync(subpattern);;}); 815 }); 816 return $alias(self, "getwd", "pwd"); 817 })(Opal.get_singleton_class(self), $nesting); 818 })($nesting[0], null, $nesting) 819}; 820 821Opal.modules["nodejs/io"] = function(Opal) {/* Generated by Opal 1.7.3 */ 822 var $klass = Opal.klass, $alias = Opal.alias, $def = Opal.def, $defs = Opal.defs, self = Opal.top, $nesting = [], nil = Opal.nil; 823 824 Opal.add_stubs('require,attr_reader,initialize,initialize_before_node_io,write,read'); 825 826 self.$require("nodejs/file"); 827 828 function executeIOAction(action) { 829 try { 830 return action(); 831 } catch (error) { 832 if (error.code === 'EACCES' || 833 error.code === 'EISDIR' || 834 error.code === 'EMFILE' || 835 error.code === 'ENOENT' || 836 error.code === 'EPERM') { 837 throw Opal.IOError.$new(error.message) 838 } 839 throw error; 840 } 841 } 842; 843 return (function($base, $super, $parent_nesting) { 844 var self = $klass($base, $super, 'IO'); 845 846 var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); 847 848 849 self.__fs__ = __fs__; 850 self.$attr_reader("lineno"); 851 $alias(self, "initialize_before_node_io", "initialize"); 852 853 $def(self, '$initialize', function $$initialize(fd, flags) { 854 var self = this; 855 856 857 if (flags == null) flags = "r"; 858 self.lineno = 0; 859 return self.$initialize_before_node_io(fd, flags); 860 }, -2); 861 $defs(self, '$write', function $$write(path, data) { 862 863 return $$('File').$write(path, data) 864 }); 865 $defs(self, '$read', function $$read(path) { 866 867 return $$('File').$read(path) 868 }); 869 return $defs(self, '$binread', function $$binread(path) { 870 871 return executeIOAction(function(){return __fs__.readFileSync(path).toString('binary')}) 872 }); 873 })($nesting[0], null, $nesting); 874}; 875 876Opal.modules["nodejs/argf"] = function(Opal) {/* Generated by Opal 1.7.3 */ 877 var $const_set = Opal.const_set, $return_val = Opal.return_val, $def = Opal.def, $eqeq = Opal.eqeq, $gvars = Opal.gvars, $truthy = Opal.truthy, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $rb_gt = Opal.rb_gt, $thrower = Opal.thrower, $not = Opal.not, $alias = Opal.alias, $a, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil; 878 879 Opal.add_stubs('new,include,filename,==,open,argv,shift,close,file,closed?,enum_for,gets,nil?,+,loop,read,-,length,>,to_a,each,attr_accessor,rewind,!,fileno,eof?,lineno='); 880 881 $const_set($nesting[0], 'ARGF', $$('Object').$new()); 882 (function(self, $parent_nesting) { 883 var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); 884 885 886 self.$include($$('Enumerable')); 887 888 $def(self, '$inspect', $return_val("ARGF")); 889 890 $def(self, '$argv', function $$argv() { 891 892 return $$('ARGV') 893 }); 894 895 $def(self, '$file', function $$file() { 896 var self = this, fn = nil, $ret_or_1 = nil; 897 if (self.file == null) self.file = nil; 898 if ($gvars.stdin == null) $gvars.stdin = nil; 899 900 901 fn = self.$filename(); 902 if ($eqeq(fn, "-")) { 903 return $gvars.stdin 904 } else { 905 return (self.file = ($truthy(($ret_or_1 = self.file)) ? ($ret_or_1) : ($$('File').$open(fn, "r")))) 906 }; 907 }); 908 909 $def(self, '$filename', function $$filename() { 910 var self = this, $ret_or_1 = nil; 911 if (self.filename == null) self.filename = nil; 912 if (self.last_filename == null) self.last_filename = nil; 913 914 915 if ($truthy(self.filename)) { 916 return self.filename 917 }; 918 if ($eqeq(self.$argv(), ["-"])) { 919 return "-" 920 } else if ($eqeq(self.$argv(), [])) { 921 if ($truthy(($ret_or_1 = self.last_filename))) { 922 return $ret_or_1 923 } else { 924 return "-" 925 } 926 } else { 927 928 self.file = nil; 929 return (self.filename = (self.last_filename = self.$argv().$shift())); 930 }; 931 }); 932 933 $def(self, '$close', function $$close() { 934 var self = this; 935 936 937 self.$file().$close(); 938 self.filename = nil; 939 return self; 940 }); 941 942 $def(self, '$closed?', function $closed$ques$1() { 943 var self = this; 944 945 return self.$file()['$closed?']() 946 }); 947 948 $def(self, '$each', function $$each($a) { 949 var block = $$each.$$p || nil, $post_args, args, self = this, l = nil; 950 951 $$each.$$p = null; 952 953 ; 954 $post_args = $slice(arguments); 955 args = $post_args; 956 if (!(block !== nil)) { 957 return self.$enum_for("each") 958 }; 959 while ($truthy((l = $send(self, 'gets', $to_a(args))))) { 960 Opal.yield1(block, l) 961 }; 962 }, -1); 963 964 $def(self, '$gets', function $$gets($a) { 965 var $post_args, args, self = this, s = nil; 966 if (self.lineno == null) self.lineno = nil; 967 968 969 $post_args = $slice(arguments); 970 args = $post_args; 971 s = $send(self.$file(), 'gets', $to_a(args)); 972 if ($truthy(s['$nil?']())) { 973 974 self.$close(); 975 s = $send(self.$file(), 'gets', $to_a(args)); 976 }; 977 if ($truthy(s)) { 978 self.lineno = $rb_plus(self.lineno, 1) 979 }; 980 return s; 981 }, -1); 982 983 $def(self, '$read', function $$read(len) { 984 var self = this, buf = nil; 985 986 987 if (len == null) len = nil; 988 buf = ""; 989 return (function(){try { var $t_break = $thrower('break'); return $send(self, 'loop', [], function $$2(){var self = $$2.$$s == null ? this : $$2.$$s, r = nil; 990 if (self.filename == null) self.filename = nil; 991 992 993 r = self.$file().$read(len); 994 if ($truthy(r)) { 995 996 buf = $rb_plus(buf, r); 997 len = $rb_minus(len, r.$length()); 998 }; 999 self.$file().$close(); 1000 if ((($truthy(len) && ($truthy($rb_gt(len, 0)))) && ($truthy(self.filename)))) { 1001 $t_break.$throw() 1002 } else { 1003 return nil 1004 };}, {$$s: self})} catch($e) { 1005 if ($e === $t_break) return $e.$v; 1006 throw $e; 1007 }})(); 1008 }, -1); 1009 1010 $def(self, '$readlines', function $$readlines($a) { 1011 var $post_args, args, self = this; 1012 1013 1014 $post_args = $slice(arguments); 1015 args = $post_args; 1016 return $send(self, 'each', $to_a(args)).$to_a(); 1017 }, -1); 1018 self.$attr_accessor("lineno"); 1019 1020 $def(self, '$rewind', function $$rewind() { 1021 var self = this, f = nil; 1022 1023 1024 self.lineno = 1; 1025 f = self.$file(); 1026 1027 try { 1028 f.$rewind() 1029 } catch ($err) { 1030 if (Opal.rescue($err, [$$('StandardError')])) { 1031 try { 1032 nil 1033 } finally { Opal.pop_exception(); } 1034 } else { throw $err; } 1035 };; 1036 return 0; 1037 }); 1038 1039 $def(self, '$fileno', function $$fileno() { 1040 var self = this; 1041 if (self.last_filename == null) self.last_filename = nil; 1042 if (self.filename == null) self.filename = nil; 1043 1044 1045 if (($not(self.filename) && ($truthy(self.last_filename)))) { 1046 return 0 1047 }; 1048 return self.$file().$fileno(); 1049 }); 1050 1051 $def(self, '$eof?', function $eof$ques$3() { 1052 var self = this; 1053 1054 return self.$file()['$eof?']() 1055 }); 1056 $alias(self, "each_line", "each"); 1057 $alias(self, "eof", "eof?"); 1058 $alias(self, "path", "filename"); 1059 $alias(self, "skip", "close"); 1060 $alias(self, "to_i", "fileno"); 1061 return $alias(self, "to_io", "file"); 1062 })(Opal.get_singleton_class($$('ARGF')), $nesting); 1063 return ($a = [1], $send($$('ARGF'), 'lineno=', $a), $a[$a.length - 1]); 1064}; 1065 1066Opal.modules["nodejs/open-uri"] = function(Opal) {/* Generated by Opal 1.7.3 */ 1067 var $module = Opal.module, $defs = Opal.defs, $nesting = [], nil = Opal.nil; 1068 1069 return (function($base) { 1070 var self = $module($base, 'OpenURI'); 1071 1072 if (self.__xmlhttprequest__ == null) self.__xmlhttprequest__ = nil; 1073 1074 1075 self.__xmlhttprequest__ = __xmlhttprequest__; 1076 var __XMLHttpRequest__ = self.__xmlhttprequest__.XMLHttpRequest; 1077 $defs(self, '$request', function $$request(uri) { 1078 1079 1080 var xhr = new __XMLHttpRequest__(); 1081 xhr.open('GET', uri, false); 1082 xhr.responseType = 'arraybuffer'; 1083 xhr.send(); 1084 return xhr; 1085 1086 }); 1087 return $defs(self, '$data', function $$data(req) { 1088 1089 1090 var arrayBuffer = req.response; 1091 var byteArray = new Uint8Array(arrayBuffer); 1092 var result = [] 1093 for (var i = 0; i < byteArray.byteLength; i++) { 1094 result.push(byteArray[i]); 1095 } 1096 return result; 1097 1098 }); 1099 })($nesting[0]) 1100}; 1101 1102Opal.modules["corelib/comparable"] = function(Opal) {/* Generated by Opal 1.7.3 */ 1103 var $truthy = Opal.truthy, $module = Opal.module, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $def = Opal.def, nil = Opal.nil, $$$ = Opal.$$$; 1104 1105 Opal.add_stubs('>,<,===,raise,class,<=>,equal?'); 1106 return (function($base) { 1107 var self = $module($base, 'Comparable'); 1108 1109 var $ret_or_1 = nil; 1110 1111 1112 1113 function normalize(what) { 1114 if (Opal.is_a(what, Opal.Integer)) { return what; } 1115 1116 if ($rb_gt(what, 0)) { return 1; } 1117 if ($rb_lt(what, 0)) { return -1; } 1118 return 0; 1119 } 1120 1121 function fail_comparison(lhs, rhs) { 1122 var class_name; 1123 (($eqeqeq(nil, ($ret_or_1 = rhs)) || (($eqeqeq(true, $ret_or_1) || (($eqeqeq(false, $ret_or_1) || (($eqeqeq($$$('Integer'), $ret_or_1) || ($eqeqeq($$$('Float'), $ret_or_1))))))))) ? (class_name = rhs.$inspect()) : (class_name = rhs.$$class)) 1124 $Kernel.$raise($$$('ArgumentError'), "comparison of " + ((lhs).$class()) + " with " + (class_name) + " failed") 1125 } 1126 1127 function cmp_or_fail(lhs, rhs) { 1128 var cmp = (lhs)['$<=>'](rhs); 1129 if (!$truthy(cmp)) fail_comparison(lhs, rhs); 1130 return normalize(cmp); 1131 } 1132 ; 1133 1134 $def(self, '$==', function $Comparable_$eq_eq$1(other) { 1135 var self = this, cmp = nil; 1136 1137 1138 if ($truthy(self['$equal?'](other))) { 1139 return true 1140 }; 1141 1142 if (self["$<=>"] == Opal.Kernel["$<=>"]) { 1143 return false; 1144 } 1145 1146 // check for infinite recursion 1147 if (self.$$comparable) { 1148 self.$$comparable = false; 1149 return false; 1150 } 1151 ; 1152 if (!$truthy((cmp = self['$<=>'](other)))) { 1153 return false 1154 }; 1155 return normalize(cmp) == 0;; 1156 }); 1157 1158 $def(self, '$>', function $Comparable_$gt$2(other) { 1159 var self = this; 1160 1161 return cmp_or_fail(self, other) > 0; 1162 }); 1163 1164 $def(self, '$>=', function $Comparable_$gt_eq$3(other) { 1165 var self = this; 1166 1167 return cmp_or_fail(self, other) >= 0; 1168 }); 1169 1170 $def(self, '$<', function $Comparable_$lt$4(other) { 1171 var self = this; 1172 1173 return cmp_or_fail(self, other) < 0; 1174 }); 1175 1176 $def(self, '$<=', function $Comparable_$lt_eq$5(other) { 1177 var self = this; 1178 1179 return cmp_or_fail(self, other) <= 0; 1180 }); 1181 1182 $def(self, '$between?', function $Comparable_between$ques$6(min, max) { 1183 var self = this; 1184 1185 1186 if ($rb_lt(self, min)) { 1187 return false 1188 }; 1189 if ($rb_gt(self, max)) { 1190 return false 1191 }; 1192 return true; 1193 }); 1194 return $def(self, '$clamp', function $$clamp(min, max) { 1195 var self = this; 1196 1197 1198 if (max == null) max = nil; 1199 1200 var c, excl; 1201 1202 if (max === nil) { 1203 // We are dealing with a new Ruby 2.7 behaviour that we are able to 1204 // provide a single Range argument instead of 2 Comparables. 1205 1206 if (!Opal.is_a(min, Opal.Range)) { 1207 $Kernel.$raise($$$('TypeError'), "wrong argument type " + (min.$class()) + " (expected Range)") 1208 } 1209 1210 excl = min.excl; 1211 max = min.end; 1212 min = min.begin; 1213 1214 if (max !== nil && excl) { 1215 $Kernel.$raise($$$('ArgumentError'), "cannot clamp with an exclusive range") 1216 } 1217 } 1218 1219 if (min !== nil && max !== nil && cmp_or_fail(min, max) > 0) { 1220 $Kernel.$raise($$$('ArgumentError'), "min argument must be smaller than max argument") 1221 } 1222 1223 if (min !== nil) { 1224 c = cmp_or_fail(self, min); 1225 1226 if (c == 0) return self; 1227 if (c < 0) return min; 1228 } 1229 1230 if (max !== nil) { 1231 c = cmp_or_fail(self, max); 1232 1233 if (c > 0) return max; 1234 } 1235 1236 return self; 1237 ; 1238 }, -2); 1239 })('::') 1240}; 1241 1242Opal.modules["pathname"] = function(Opal) {/* Generated by Opal 1.7.3 */ 1243 var $klass = Opal.klass, $const_set = Opal.const_set, $regexp = Opal.regexp, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $def = Opal.def, $defs = Opal.defs, $to_ary = Opal.to_ary, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $return_ivar = Opal.return_ivar, $neqeq = Opal.neqeq, $rb_plus = Opal.rb_plus, $not = Opal.not, $thrower = Opal.thrower, $alias = Opal.alias, $module = Opal.module, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$; 1244 1245 Opal.add_stubs('require,include,quote,===,to_s,path,respond_to?,to_path,is_a?,nil?,raise,class,==,new,pwd,attr_reader,!,relative?,chop_basename,basename,=~,source,[],rindex,sub,absolute?,expand_path,plus,unshift,length,!=,empty?,first,shift,+,join,dirname,pop,reverse_each,directory?,extname,<=>,nonzero?,proc,casecmp,cleanpath,inspect,include?,fill,map,entries'); 1246 1247 self.$require("corelib/comparable"); 1248 (function($base, $super, $parent_nesting) { 1249 var self = $klass($base, $super, 'Pathname'); 1250 1251 var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; 1252 1253 $proto.path = nil; 1254 1255 self.$include($$('Comparable')); 1256 $const_set($nesting[0], 'SEPARATOR_PAT', $regexp([$$('Regexp').$quote($$$($$('File'), 'SEPARATOR'))])); 1257 1258 $def(self, '$initialize', function $$initialize(path) { 1259 var self = this; 1260 1261 1262 if ($eqeqeq($$('Pathname'), path)) { 1263 self.path = path.$path().$to_s() 1264 } else if ($truthy(path['$respond_to?']("to_path"))) { 1265 self.path = path.$to_path() 1266 } else if ($truthy(path['$is_a?']($$('String')))) { 1267 self.path = path 1268 } else if ($truthy(path['$nil?']())) { 1269 self.$raise($$('TypeError'), "no implicit conversion of nil into String") 1270 } else { 1271 self.$raise($$('TypeError'), "no implicit conversion of " + (path.$class()) + " into String") 1272 }; 1273 if ($eqeq(self.path, "\u0000")) { 1274 return self.$raise($$('ArgumentError')) 1275 } else { 1276 return nil 1277 }; 1278 }); 1279 $defs(self, '$pwd', function $$pwd() { 1280 var self = this; 1281 1282 return self.$new($$('Dir').$pwd()) 1283 }); 1284 self.$attr_reader("path"); 1285 1286 $def(self, '$==', function $Pathname_$eq_eq$1(other) { 1287 var self = this; 1288 1289 return other.$path()['$=='](self.path) 1290 }); 1291 1292 $def(self, '$absolute?', function $Pathname_absolute$ques$2() { 1293 var self = this; 1294 1295 return self['$relative?']()['$!']() 1296 }); 1297 1298 $def(self, '$relative?', function $Pathname_relative$ques$3() { 1299 var $a, $b, self = this, path = nil, r = nil; 1300 1301 1302 path = self.path; 1303 while ($truthy((r = self.$chop_basename(path)))) { 1304 $b = r, $a = $to_ary($b), (path = ($a[0] == null ? nil : $a[0])), $b 1305 }; 1306 return path['$=='](""); 1307 }); 1308 1309 $def(self, '$chop_basename', function $$chop_basename(path) { 1310 var base = nil; 1311 1312 1313 base = $$('File').$basename(path); 1314 if ($truthy($$('Regexp').$new("^" + ($$$($$('Pathname'), 'SEPARATOR_PAT').$source()) + "?$")['$=~'](base))) { 1315 return nil 1316 } else { 1317 return [path['$[]'](0, path.$rindex(base)), base] 1318 }; 1319 }); 1320 1321 $def(self, '$root?', function $Pathname_root$ques$4() { 1322 var self = this; 1323 1324 return self.path['$==']("/") 1325 }); 1326 1327 $def(self, '$parent', function $$parent() { 1328 var self = this, new_path = nil; 1329 1330 1331 new_path = self.path.$sub(/\/([^\/]+\/?$)/, ""); 1332 if ($eqeq(new_path, "")) { 1333 new_path = ($truthy(self['$absolute?']()) ? ("/") : (".")) 1334 }; 1335 return $$('Pathname').$new(new_path); 1336 }); 1337 1338 $def(self, '$sub', function $$sub($a) { 1339 var $post_args, args, self = this; 1340 1341 1342 $post_args = $slice(arguments); 1343 args = $post_args; 1344 return $$('Pathname').$new($send(self.path, 'sub', $to_a(args))); 1345 }, -1); 1346 1347 $def(self, '$cleanpath', function $$cleanpath() { 1348 var self = this; 1349 1350 return Opal.normalize(self.path) 1351 }); 1352 1353 $def(self, '$to_path', $return_ivar("path")); 1354 1355 $def(self, '$hash', $return_ivar("path")); 1356 1357 $def(self, '$expand_path', function $$expand_path() { 1358 var self = this; 1359 1360 return $$('Pathname').$new($$('File').$expand_path(self.path)) 1361 }); 1362 1363 $def(self, '$+', function $Pathname_$plus$5(other) { 1364 var self = this; 1365 1366 1367 if (!$eqeqeq($$('Pathname'), other)) { 1368 other = $$('Pathname').$new(other) 1369 }; 1370 return $$('Pathname').$new(self.$plus(self.path, other.$to_s())); 1371 }); 1372 1373 $def(self, '$plus', function $$plus(path1, path2) { 1374 var $a, $b, self = this, prefix2 = nil, index_list2 = nil, basename_list2 = nil, r2 = nil, basename2 = nil, prefix1 = nil, $ret_or_1 = nil, r1 = nil, basename1 = nil, suffix2 = nil; 1375 1376 1377 prefix2 = path2; 1378 index_list2 = []; 1379 basename_list2 = []; 1380 while ($truthy((r2 = self.$chop_basename(prefix2)))) { 1381 1382 $b = r2, $a = $to_ary($b), (prefix2 = ($a[0] == null ? nil : $a[0])), (basename2 = ($a[1] == null ? nil : $a[1])), $b; 1383 index_list2.$unshift(prefix2.$length()); 1384 basename_list2.$unshift(basename2); 1385 }; 1386 if ($neqeq(prefix2, "")) { 1387 return path2 1388 }; 1389 prefix1 = path1; 1390 while ($truthy(true)) { 1391 1392 while ($truthy(($truthy(($ret_or_1 = basename_list2['$empty?']()['$!']())) ? (basename_list2.$first()['$=='](".")) : ($ret_or_1)))) { 1393 1394 index_list2.$shift(); 1395 basename_list2.$shift(); 1396 }; 1397 if (!$truthy((r1 = self.$chop_basename(prefix1)))) { 1398 break 1399 }; 1400 $b = r1, $a = $to_ary($b), (prefix1 = ($a[0] == null ? nil : $a[0])), (basename1 = ($a[1] == null ? nil : $a[1])), $b; 1401 if ($eqeq(basename1, ".")) { 1402 continue 1403 }; 1404 if ((($eqeq(basename1, "..") || ($truthy(basename_list2['$empty?']()))) || ($neqeq(basename_list2.$first(), "..")))) { 1405 1406 prefix1 = $rb_plus(prefix1, basename1); 1407 break; 1408 }; 1409 index_list2.$shift(); 1410 basename_list2.$shift(); 1411 }; 1412 r1 = self.$chop_basename(prefix1); 1413 if (($not(r1) && ($truthy($regexp([$$('SEPARATOR_PAT')])['$=~']($$('File').$basename(prefix1)))))) { 1414 while ($truthy(($truthy(($ret_or_1 = basename_list2['$empty?']()['$!']())) ? (basename_list2.$first()['$==']("..")) : ($ret_or_1)))) { 1415 1416 index_list2.$shift(); 1417 basename_list2.$shift(); 1418 } 1419 }; 1420 if ($not(basename_list2['$empty?']())) { 1421 1422 suffix2 = path2['$[]'](Opal.Range.$new(index_list2.$first(), -1, false)); 1423 if ($truthy(r1)) { 1424 return $$('File').$join(prefix1, suffix2) 1425 } else { 1426 return $rb_plus(prefix1, suffix2) 1427 }; 1428 } else if ($truthy(r1)) { 1429 return prefix1 1430 } else { 1431 return $$('File').$dirname(prefix1) 1432 }; 1433 }); 1434 1435 $def(self, '$join', function $$join($a) {try { var $t_return = $thrower('return'); 1436 var $post_args, args, self = this, result = nil; 1437 1438 1439 $post_args = $slice(arguments); 1440 args = $post_args; 1441 if ($truthy(args['$empty?']())) { 1442 return self 1443 }; 1444 result = args.$pop(); 1445 if (!$eqeqeq($$('Pathname'), result)) { 1446 result = $$('Pathname').$new(result) 1447 }; 1448 if ($truthy(result['$absolute?']())) { 1449 return result 1450 }; 1451 $send(args, 'reverse_each', [], function $$6(arg){ 1452 1453 if (arg == null) arg = nil; 1454 if (!$eqeqeq($$('Pathname'), arg)) { 1455 arg = $$('Pathname').$new(arg) 1456 }; 1457 result = $rb_plus(arg, result); 1458 if ($truthy(result['$absolute?']())) { 1459 $t_return.$throw(result) 1460 } else { 1461 return nil 1462 };}, {$$ret: $t_return}); 1463 return $rb_plus(self, result);} catch($e) { 1464 if ($e === $t_return) return $e.$v; 1465 throw $e; 1466 } 1467 }, -1); 1468 1469 $def(self, '$split', function $$split() { 1470 var self = this; 1471 1472 return [self.$dirname(), self.$basename()] 1473 }); 1474 1475 $def(self, '$dirname', function $$dirname() { 1476 var self = this; 1477 1478 return $$('Pathname').$new($$('File').$dirname(self.path)) 1479 }); 1480 1481 $def(self, '$basename', function $$basename() { 1482 var self = this; 1483 1484 return $$('Pathname').$new($$('File').$basename(self.path)) 1485 }); 1486 1487 $def(self, '$directory?', function $Pathname_directory$ques$7() { 1488 var self = this; 1489 1490 return $$('File')['$directory?'](self.path) 1491 }); 1492 1493 $def(self, '$extname', function $$extname() { 1494 var self = this; 1495 1496 return $$('File').$extname(self.path) 1497 }); 1498 1499 $def(self, '$<=>', function $Pathname_$lt_eq_gt$8(other) { 1500 var self = this; 1501 1502 return self.$path()['$<=>'](other.$path()) 1503 }); 1504 $const_set($nesting[0], 'SAME_PATHS', ($truthy($$$($$('File'), 'FNM_SYSCASE')['$nonzero?']()) ? ($send(self, 'proc', [], function $Pathname$9(a, b){ 1505 1506 if (a == null) a = nil; 1507 if (b == null) b = nil; 1508 return a.$casecmp(b)['$=='](0);})) : ($send(self, 'proc', [], function $Pathname$10(a, b){ 1509 1510 if (a == null) a = nil; 1511 if (b == null) b = nil; 1512 return a['$=='](b);})))); 1513 1514 $def(self, '$relative_path_from', function $$relative_path_from(base_directory) { 1515 var $a, $b, self = this, dest_directory = nil, dest_prefix = nil, dest_names = nil, r = nil, basename = nil, base_prefix = nil, base_names = nil, $ret_or_1 = nil, $ret_or_2 = nil, relpath_names = nil; 1516 1517 1518 dest_directory = self.$cleanpath().$to_s(); 1519 base_directory = base_directory.$cleanpath().$to_s(); 1520 dest_prefix = dest_directory; 1521 dest_names = []; 1522 while ($truthy((r = self.$chop_basename(dest_prefix)))) { 1523 1524 $b = r, $a = $to_ary($b), (dest_prefix = ($a[0] == null ? nil : $a[0])), (basename = ($a[1] == null ? nil : $a[1])), $b; 1525 if ($neqeq(basename, ".")) { 1526 dest_names.$unshift(basename) 1527 }; 1528 }; 1529 base_prefix = base_directory; 1530 base_names = []; 1531 while ($truthy((r = self.$chop_basename(base_prefix)))) { 1532 1533 $b = r, $a = $to_ary($b), (base_prefix = ($a[0] == null ? nil : $a[0])), (basename = ($a[1] == null ? nil : $a[1])), $b; 1534 if ($neqeq(basename, ".")) { 1535 base_names.$unshift(basename) 1536 }; 1537 }; 1538 if (!$truthy($$('SAME_PATHS')['$[]'](dest_prefix, base_prefix))) { 1539 self.$raise($$('ArgumentError'), "different prefix: " + (dest_prefix.$inspect()) + " and " + (base_directory.$inspect())) 1540 }; 1541 while ($truthy(($truthy(($ret_or_1 = ($truthy(($ret_or_2 = dest_names['$empty?']()['$!']())) ? (base_names['$empty?']()['$!']()) : ($ret_or_2)))) ? ($$('SAME_PATHS')['$[]'](dest_names.$first(), base_names.$first())) : ($ret_or_1)))) { 1542 1543 dest_names.$shift(); 1544 base_names.$shift(); 1545 }; 1546 if ($truthy(base_names['$include?'](".."))) { 1547 self.$raise($$('ArgumentError'), "base_directory has ..: " + (base_directory.$inspect())) 1548 }; 1549 base_names.$fill(".."); 1550 relpath_names = $rb_plus(base_names, dest_names); 1551 if ($truthy(relpath_names['$empty?']())) { 1552 return $$('Pathname').$new(".") 1553 } else { 1554 return $$('Pathname').$new($send($$('File'), 'join', $to_a(relpath_names))) 1555 }; 1556 }); 1557 1558 $def(self, '$entries', function $$entries() { 1559 var self = this; 1560 1561 return $send($$('Dir').$entries(self.path), 'map', [], function $$11(f){var self = $$11.$$s == null ? this : $$11.$$s; 1562 1563 1564 if (f == null) f = nil; 1565 return self.$class().$new(f);}, {$$s: self}) 1566 }); 1567 $alias(self, "===", "=="); 1568 $alias(self, "eql?", "=="); 1569 $alias(self, "to_s", "to_path"); 1570 return $alias(self, "to_str", "to_path"); 1571 })($nesting[0], null, $nesting); 1572 return (function($base, $parent_nesting) { 1573 var self = $module($base, 'Kernel'); 1574 1575 var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); 1576 1577 return $def(self, '$Pathname', function $$Pathname(path) { 1578 1579 return $$('Pathname').$new(path) 1580 }) 1581 })($nesting[0], $nesting); 1582}; 1583 1584Opal.modules["nodejs/pathname"] = function(Opal) {/* Generated by Opal 1.7.3 */ 1585 var $klass = Opal.klass, $def = Opal.def, $return_ivar = Opal.return_ivar, self = Opal.top, $nesting = [], nil = Opal.nil; 1586 1587 Opal.add_stubs('require,include,to_str,!,absolute?'); 1588 1589 self.$require("pathname"); 1590 return (function($base, $super, $parent_nesting) { 1591 var self = $klass($base, $super, 'Pathname'); 1592 1593 var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype; 1594 if (self.__path__ == null) self.__path__ = nil; 1595 1596 $proto.path = nil; 1597 1598 self.$include($$('Comparable')); 1599 self.__path__ = __path__; 1600 1601 $def(self, '$absolute?', function $Pathname_absolute$ques$1() { 1602 var self = this; 1603 1604 return __path__.isAbsolute(self.path.$to_str()) 1605 }); 1606 1607 $def(self, '$relative?', function $Pathname_relative$ques$2() { 1608 var self = this; 1609 1610 return self['$absolute?']()['$!']() 1611 }); 1612 return $def(self, '$to_path', $return_ivar("path")); 1613 })($nesting[0], null, $nesting); 1614}; 1615 1616Opal.modules["nodejs/env"] = function(Opal) {/* Generated by Opal 1.7.3 */ 1617 var $const_set = Opal.const_set, $def = Opal.def, $truthy = Opal.truthy, $return_val = Opal.return_val, $send = Opal.send, $alias = Opal.alias, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil; 1618 1619 Opal.add_stubs('new,to_s,key?,[],raise,to_h,keys,merge'); 1620 1621 $const_set($nesting[0], 'ENV', $$('Object').$new()); 1622 return (function(self, $parent_nesting) { 1623 var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting); 1624 1625 1626 1627 $def(self, '$[]', function $$$1(name) { 1628 1629 return process.env[name] || nil 1630 }); 1631 1632 $def(self, '$[]=', function $$$eq$2(name, value) { 1633 1634 return process.env[name.$to_s()] = value.$to_s() 1635 }); 1636 1637 $def(self, '$key?', function $key$ques$3(name) { 1638 1639 return process.env.hasOwnProperty(name) 1640 }); 1641 1642 $def(self, '$empty?', function $empty$ques$4() { 1643 1644 return Object.keys(process.env).length === 0; 1645 }); 1646 1647 $def(self, '$keys', function $$keys() { 1648 1649 return Object.keys(process.env); 1650 }); 1651 1652 $def(self, '$delete', function $delete$5(name) { 1653 1654 1655 var value = process.env[name] || nil; 1656 delete process.env[name]; 1657 return value; 1658 1659 }); 1660 1661 $def(self, '$fetch', function $$fetch(key, default_value) { 1662 var block = $$fetch.$$p || nil, self = this; 1663 1664 $$fetch.$$p = null; 1665 1666 ; 1667 ; 1668 if ($truthy(self['$key?'](key))) { 1669 return self['$[]'](key) 1670 }; 1671 if ((block !== nil)) { 1672 return Opal.yield1(block, key) 1673 }; 1674 if (!$truthy(typeof(default_value) === 'undefined')) { 1675 return default_value 1676 }; 1677 return self.$raise($$('KeyError'), "key not found"); 1678 }, -2); 1679 1680 $def(self, '$to_s', $return_val("ENV")); 1681 1682 $def(self, '$to_h', function $$to_h() { 1683 var self = this; 1684 1685 return $send(self.$keys(), 'to_h', [], function $$6(k){var self = $$6.$$s == null ? this : $$6.$$s; 1686 1687 1688 if (k == null) k = nil; 1689 return [k, self['$[]'](k)];}, {$$s: self}) 1690 }); 1691 1692 $def(self, '$merge', function $$merge(keys) { 1693 var self = this; 1694 1695 return self.$to_h().$merge(keys) 1696 }); 1697 $alias(self, "has_key?", "key?"); 1698 $alias(self, "include?", "key?"); 1699 $alias(self, "inspect", "to_s"); 1700 $alias(self, "member?", "key?"); 1701 return $alias(self, "to_hash", "to_h"); 1702 })(Opal.get_singleton_class($$('ENV')), $nesting); 1703}; 1704 1705Opal.modules["nodejs"] = function(Opal) {/* Generated by Opal 1.7.3 */ 1706 var self = Opal.top, nil = Opal.nil; 1707 1708 Opal.add_stubs('require'); 1709 1710 self.$require("nodejs/base"); 1711 self.$require("nodejs/file"); 1712 self.$require("nodejs/dir"); 1713 self.$require("nodejs/io"); 1714 self.$require("nodejs/argf"); 1715 self.$require("nodejs/open-uri"); 1716 self.$require("nodejs/pathname"); 1717 return self.$require("nodejs/env"); 1718}; 1719 1720