Class: DiscourseCli::Editor

Inherits:
Object
  • Object
show all
Defined in:
lib/discourse_cli/editor.rb

Instance Method Summary collapse

Constructor Details

#initialize(spawn: nil) ⇒ Editor

Returns a new instance of Editor.



8
9
10
# File 'lib/discourse_cli/editor.rb', line 8

def initialize(spawn: nil)
  @spawn = spawn || method(:default_spawn)
end

Instance Method Details

#open(initial_content = "") ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/discourse_cli/editor.rb', line 12

def open(initial_content = "")
  Tempfile.create(["dsc", ".md"]) do |f|
    f.write(initial_content)
    f.flush
    @spawn.call(f.path)
    f.rewind
    f.read
  end
end