Class: SensuCli::Editor

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu-cli/editor.rb

Instance Method Summary collapse

Instance Method Details

#create_stash(create_path) ⇒ Object



7
8
9
10
# File 'lib/sensu-cli/editor.rb', line 7

def create_stash(create_path)
  file = temp_file({:path => create_path, :content => {:timestamp => Time.now.to_i }})
  edit(file)
end

#edit(file) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/sensu-cli/editor.rb', line 12

def edit(file)
  ENV['EDITOR'] ? editor = ENV['EDITOR'] : editor = 'vi'
  system("#{editor} #{file}")
  begin
    JSON.parse(File.read(file))
  rescue JSON::ParserError
    puts "The stash you created has Invalid JSON."
    exit
  end
end

#temp_file(template) ⇒ Object



23
24
25
26
27
28
# File 'lib/sensu-cli/editor.rb', line 23

def temp_file(template)
  file = Tempfile.new('sensu')
  file.write(JSON.pretty_generate(template))
  file.close
  file.path
end