# # # # # # # # #
# /48/aorta.rb
#
# by               Jan Lelis
# e-mail:          mail@janlelis.de
# type/version:    ruby 
# snippet url:     http://rbJL.net/48/aorta.rb
# original post:   http://rbJL.net/48-small-ruby-cli-improvements-part-4-edit-ruby-objects-using-yaml
# license:         CC-BY (DE)
#
# (c) 2011 Jan Lelis.

# why the luck stiff's "object aorta"
# http://rubyforge.org/snippet/detail.php?type=snippet&id=22

require 'yaml'
def aorta( obj )
  tempfile = File.join('/tmp',"yobj_#{ Time.now.to_i }")
  File.open( tempfile, 'w' ) { |f| f << obj.to_yaml }
  system( "#{ ENV['EDITOR'] || 'vi' } #{ tempfile }" )
  return obj unless File.exists?( tempfile )
  content = YAML::load( File.open( tempfile ) )
  File.delete( tempfile )
  content
end