Class: CARPS::Editor
- Inherits:
-
SystemConfig
- Object
- YamlConfig
- SystemConfig
- CARPS::Editor
- Defined in:
- lib/carps/util/editor.rb
Overview
Expects a field called “launch_editor”
Class Method Summary collapse
Instance Method Summary collapse
-
#edit(msg) ⇒ Object
Edit a string.
-
#initialize(editor, wait_for_confirm = false) ⇒ Editor
constructor
A new instance of Editor.
- #parse_yaml(config) ⇒ Object
Methods inherited from SystemConfig
Methods inherited from YamlConfig
Constructor Details
#initialize(editor, wait_for_confirm = false) ⇒ Editor
Returns a new instance of Editor.
37 38 39 40 |
# File 'lib/carps/util/editor.rb', line 37 def initialize editor, wait_for_confirm = false @editor = editor @wait_confirm = wait_for_confirm end |
Class Method Details
.filepath ⇒ Object
33 34 35 |
# File 'lib/carps/util/editor.rb', line 33 def Editor.filepath "editor.yaml" end |
Instance Method Details
#edit(msg) ⇒ Object
Edit a string
Performs an untaint operation
Not re-entrant
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/carps/util/editor.rb', line 52 def edit msg begin dir = Dir.tmpdir.untaint unless File.exists?(dir) FileUtils.mkdir dir end file = Tempfile.new "carp_edit", dir path = file.path file.write "# Lines starting with # will be ignored.\n" + msg file.close contents = edit_file path contents.untaint lines = contents.split /\n/ lines.reject! do |line| line[0] == '#' end lines.join "\n" rescue StandardError => e UI::put_error e.to_s nil end end |
#parse_yaml(config) ⇒ Object
42 43 44 45 |
# File 'lib/carps/util/editor.rb', line 42 def parse_yaml config @editor = read_conf config, "launch_editor" @wait_confirm = read_conf config, "wait" end |