Sha256: aadb02a8caf8f23fc483c29370f12422575de0e13781be606fc23b9c2ac52cf5

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'folio/fileobject'

module Folio

  class Document < FileObject

    def intialize(path)
      super
      raise FileNotFound unless ::File.file?(@path)
      raise FileNotFound if ::File.symlink?(@path)
    end

    #--
    # Polymorphism
    #++

    def file? ; true ; end

    #--
    # FileTest::
    #++

    def executable?       ; ::FileTest.executable?(path)       ; end
    def executable_real?  ; ::FileTest.executable_real?(path)  ; end

    #--
    # File::
    #++

    def read              ; ::File.read(path)                  ; end

    def readlines         ; ::File.readlines(path)             ; end

    # TODO: how to handle unkinking (b/c file no longer exists)
    def unlink            ; ::File.unlink(path)                ; end
    def delete            ; ::File.delete(path)                ; end

    #--
    # File.open
    #++

    def open(mode, &block)
      ::File.open(path, mode, &block)
    end

    def truncate(size)
      ::File.open(path, 'w'){|f| f.truncate(size)}
    end

    #--  
    # Can we handle other modes besides read this way?
    #++

    #flock(mode)       ; _file.flock(mode)                   ; end

    #def method_missing(s, *a, &b)
    #  _file.send(s, *a, &b)
    #end

    #private

    #def _file         ; @_file ||= ::File.new(path)           ; end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
folio-0.1.0 lib/folio/document.rb