Sha256: 95bfcedcf2ece39c71c74d16466f68d5d18ed7621e456a9e12af8a196a51db99

Contents?: true

Size: 784 Bytes

Versions: 6

Compression:

Stored size: 784 Bytes

Contents

class NSString

  def document
    @@sugarcube_docs ||= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
    return self if self.hasPrefix(@@sugarcube_docs)

    @@sugarcube_docs.stringByAppendingPathComponent(self)
  end

  def exists?
    NSFileManager.defaultManager.fileExistsAtPath(self.document)
  end

  def remove!
    ptr = Pointer.new(:id)
    NSFileManager.defaultManager.removeItemAtPath(self.document, error:ptr)
    ptr[0]
  end

  def resource
    @@sugarcube_resources ||= NSBundle.mainBundle.resourcePath
    return self if self.hasPrefix(@@sugarcube_resources)

    @@sugarcube_resources.stringByAppendingPathComponent(self)
  end

  def resource_exists?
    NSFileManager.defaultManager.fileExistsAtPath(self.resource)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sugarcube-0.13.5 lib/sugarcube/nsstring_files.rb
sugarcube-0.13.4 lib/sugarcube/nsstring_files.rb
sugarcube-0.13.3 lib/sugarcube/nsstring_files.rb
sugarcube-0.13.2 lib/sugarcube/nsstring_files.rb
sugarcube-0.13 lib/sugarcube/nsstring_files.rb
sugarcube-0.12 lib/sugarcube/nsstring_files.rb