Sha256: 7bf020230bb112f327c5ca009eed8063e8c82f703bb5b456ddbb8e2c99809e27

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 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

    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

11 entries across 11 versions & 1 rubygems

Version Path
opal-0.8.1 opal/corelib/file.rb
opal-0.8.1.rc1 opal/corelib/file.rb
opal-0.8.0 opal/corelib/file.rb
opal-0.8.0.rc3 opal/corelib/file.rb
opal-0.8.0.rc2 opal/corelib/file.rb
opal-0.8.0.rc1 opal/corelib/file.rb
opal-0.8.0.beta1 opal/corelib/file.rb
opal-0.7.2 opal/corelib/file.rb
opal-0.7.1 opal/corelib/file.rb
opal-0.7.0 opal/corelib/file.rb
opal-0.7.0.rc1 opal/corelib/file.rb