Method: NA.save_search

Defined in:
lib/na/next_action.rb

.save_search(title, search) ⇒ Object



831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
# File 'lib/na/next_action.rb', line 831

def save_search(title, search)
  file = database_path(file: 'saved_searches.yml')
  searches = load_searches
  title = title.gsub(/[^a-z0-9]/, '_').gsub(/_+/, '_')

  if searches.key?(title)
    res = yn('Overwrite existing definition?', default: true)
    notify("#{NA.theme[:error]}Cancelled", exit_code: 0) unless res

  end

  searches[title] = search
  File.open(file, 'w') { |f| f.puts(YAML.dump(searches)) }
  NA.notify("#{NA.theme[:success]}Search #{NA.theme[:filename]}#{title}#{NA.theme[:success]} saved", exit_code: 0)
end