Class: Kward::PromptInterface::EditorFileMarker
- Inherits:
-
Object
- Object
- Kward::PromptInterface::EditorFileMarker
- Defined in:
- lib/kward/prompt_interface/editor/file_marker.rb
Overview
Tracks the on-disk identity and original content for an editor buffer.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #changed_on_disk?(new_file: false) ⇒ Boolean
-
#initialize(path:, content:, new_file: false) ⇒ EditorFileMarker
constructor
A new instance of EditorFileMarker.
- #refresh(content = @content) ⇒ Object
Constructor Details
#initialize(path:, content:, new_file: false) ⇒ EditorFileMarker
Returns a new instance of EditorFileMarker.
11 12 13 14 15 16 |
# File 'lib/kward/prompt_interface/editor/file_marker.rb', line 11 def initialize(path:, content:, new_file: false) @path = path.to_s @content = content.to_s @digest = Digest::SHA256.hexdigest(@content) refresh unless new_file end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
9 10 11 |
# File 'lib/kward/prompt_interface/editor/file_marker.rb', line 9 def content @content end |
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
9 10 11 |
# File 'lib/kward/prompt_interface/editor/file_marker.rb', line 9 def digest @digest end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
9 10 11 |
# File 'lib/kward/prompt_interface/editor/file_marker.rb', line 9 def mtime @mtime end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
9 10 11 |
# File 'lib/kward/prompt_interface/editor/file_marker.rb', line 9 def size @size end |
Instance Method Details
#changed_on_disk?(new_file: false) ⇒ Boolean
29 30 31 32 33 34 35 36 37 |
# File 'lib/kward/prompt_interface/editor/file_marker.rb', line 29 def changed_on_disk?(new_file: false) return false if new_file && !File.exist?(@path) return true if new_file && File.exist?(@path) return true unless File.exist?(@path) File.read(@path) != @content rescue StandardError true end |
#refresh(content = @content) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kward/prompt_interface/editor/file_marker.rb', line 18 def refresh(content = @content) @content = content.to_s @digest = Digest::SHA256.hexdigest(@content) stat = File.stat(@path) @mtime = stat.mtime @size = stat.size rescue StandardError @mtime = nil @size = nil end |