Sha256: 96ded792fcfcf5ded8a84fd9e82ff3229455f41b28eab4993fc3044350a2d55f

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

class File < IO
  Separator = SEPARATOR = '/'
  ALT_SEPARATOR = nil
  PATH_SEPARATOR = ':'

  class << self
    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
    alias realpath expand_path

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

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

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

    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

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

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
opal-0.9.4 opal/corelib/file.rb
opal-0.9.3 opal/corelib/file.rb
opal-0.9.2 opal/corelib/file.rb
opal-0.9.0 opal/corelib/file.rb
opal-0.9.0.rc1 opal/corelib/file.rb
opal-0.9.0.beta2 opal/corelib/file.rb
opal-0.9.0.beta1 opal/corelib/file.rb
opal-wedge-0.9.0.dev opal/corelib/file.rb