Class: Changi::Reader::MultilineReader

Inherits:
Object
  • Object
show all
Defined in:
lib/changi/reader/multiline_reader.rb

Instance Method Summary collapse

Instance Method Details

#read(attribute, owner) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/changi/reader/multiline_reader.rb', line 6

def read attribute, owner
  tmpfile = Tempfile.new 'changi'

  intro tmpfile, attribute

  unless system "#{editor} '#{tmpfile.path.strip}'"
    abort 'editor returned with non-zero exit status, abort'
  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