Class: XRB::FileBuffer
- Inherits:
-
Object
- Object
- XRB::FileBuffer
- Defined in:
- lib/xrb/buffer.rb
Overview
Represents a file buffer with a given path.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
- #the path name of the buffer.(pathnameofthebuffer.) ⇒ Object readonly
Instance Method Summary collapse
- #encoding ⇒ Object
-
#freeze ⇒ Object
Freeze the buffer, caching the contents of the file.
-
#initialize(path) ⇒ FileBuffer
constructor
Create a new file buffer from a file path.
-
#read ⇒ Object
Read the contents of the file into the buffer.
- #to_buffer ⇒ Object
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
#path ⇒ Object (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
#encoding ⇒ Object
81 82 83 |
# File 'lib/xrb/buffer.rb', line 81 def encoding read.encoding end |
#freeze ⇒ Object
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 |
#read ⇒ Object
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 |