Class: Pvectl::EditorSession
- Inherits:
-
Object
- Object
- Pvectl::EditorSession
- Defined in:
- lib/pvectl/editor_session.rb
Overview
Manages the editor lifecycle for interactive config editing.
Creates a temporary file with content, opens it in an editor, reads the result, and supports a retry loop with error injection when validation fails.
Constant Summary collapse
- ERROR_SEPARATOR =
"# -----------------------------------------------"
Instance Method Summary collapse
-
#edit(original_content) ⇒ String?
Opens content in an editor and returns the edited result.
-
#initialize(editor: nil, validator: nil) ⇒ EditorSession
constructor
Creates a new EditorSession.
Constructor Details
#initialize(editor: nil, validator: nil) ⇒ EditorSession
Creates a new EditorSession.
35 36 37 38 |
# File 'lib/pvectl/editor_session.rb', line 35 def initialize(editor: nil, validator: nil) @editor = editor || method(:system_editor) @validator = validator end |
Instance Method Details
#edit(original_content) ⇒ String?
Opens content in an editor and returns the edited result.
Creates a temp file, invokes the editor, and reads back the content. Supports validation with retry loop and error injection.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pvectl/editor_session.rb', line 48 def edit(original_content) tempfile = Tempfile.new(["pvectl-edit-", ".yaml"]) tempfile.write(original_content) tempfile.flush path = tempfile.path edit_loop(path, original_content) ensure tempfile&.close tempfile&.unlink end |