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.



63
64
65
66
# File 'lib/xrb/buffer.rb', line 63

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

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



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

attr :path

Instance Method Details

#encodingObject



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

def encoding
	read.encoding
end

#freezeObject

Freeze the buffer, caching the contents of the file.



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

def freeze
	return self if frozen?
	
	read
	
	super
end

#readObject

Read the contents of the file into the buffer.



87
88
89
# File 'lib/xrb/buffer.rb', line 87

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

#to_bufferObject



92
93
94
# File 'lib/xrb/buffer.rb', line 92

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