6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/changi/reader/multiline_reader.rb', line 6
def read attribute, _
tmpfile = Tempfile.new 'changi'
intro tmpfile, attribute
rc = system "#{editor} '#{tmpfile.path.strip}'"
if rc == false
abort 'editor returned with non-zero exit status, abort'
elsif rc.nil?
puts "editor '#{editor}' not found, trying nano..."
unless system "name '#{tmpfile.path.strip}'"
abort 'nano not found or non-zero exit status, abort'
end
end
read_and_strip(tmpfile).tap do |data|
if attribute[:opts][:required] && data.empty?
abort "required #{attribute[:name]} attribute empty, abort"
end
end
ensure
tmpfile.close
tmpfile.unlink
end
|