class SensuCli::Editor

Public Instance Methods

create_stash(create_path) click to toggle source
# File lib/sensu-cli/editor.rb, line 6
def create_stash(create_path)
  file = temp_file(:path => create_path, :content => { :timestamp => Time.now.to_i })
  edit(file)
end
edit(file) click to toggle source
# File lib/sensu-cli/editor.rb, line 11
def edit(file)
  editor = ENV['EDITOR'] ? ENV['EDITOR'] : 'vi'
  system("#{editor} #{file}")
  begin
    JSON.parse(File.read(file))
  rescue JSON::ParserError
    SensuCli::die(1, 'The stash you created has invalid JSON.')
  end
end
temp_file(template) click to toggle source
# File lib/sensu-cli/editor.rb, line 21
def temp_file(template)
  file = Tempfile.new('sensu')
  file.write(JSON.pretty_generate(template))
  file.close
  file.path
end