Class: XRB::FileBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/xrb/buffer.rb

Overview

Represents a file buffer with a given path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileBuffer

Create a new file buffer from a file path.



65
66
67
68
# File 'lib/xrb/buffer.rb', line 65

def initialize(path)
	@path = path
	@cache = nil
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



80
81
82
# File 'lib/xrb/buffer.rb', line 80

def path
  @path
end

#the path name of the buffer.(pathnameofthebuffer.) ⇒ Object (readonly)



80
# File 'lib/xrb/buffer.rb', line 80

attr :path

Instance Method Details

#encodingObject



83
84
85
# File 'lib/xrb/buffer.rb', line 83

def encoding
	read.encoding
end

#freezeObject

Freeze the buffer, caching the contents of the file.



71
72
73
74
75
76
77
# File 'lib/xrb/buffer.rb', line 71

def freeze
	return self if frozen?
	
	read
	
	super
end

#readObject

Read the contents of the file into the buffer.



89
90
91
# File 'lib/xrb/buffer.rb', line 89

def read
	@cache ||= File.read(@path).freeze
end

#to_bufferObject



94
95
96
# File 'lib/xrb/buffer.rb', line 94

def to_buffer
	Buffer.new(self.read, @path)
end