class Workspace

Public Class Methods

new() click to toggle source
# File lib/notes_cli/models/workspace.rb, line 6
def initialize
  FileUtils.touch(NotesCli::CONFIG_PATH) unless File.file?(NotesCli::CONFIG_PATH)
end

Public Instance Methods

create_note(notebook, title) click to toggle source
# File lib/notes_cli/models/workspace.rb, line 10
def create_note(notebook, title)
  NoteCreator.new(notebook, title, notebook_path(notebook), workspace_path).call
end
delete_note(notebook, title) click to toggle source
# File lib/notes_cli/models/workspace.rb, line 14
def delete_note(notebook, title)
  NoteDeleter.new(notebook, title, notebook_path(notebook), workspace_path).call
end
editor() click to toggle source
# File lib/notes_cli/models/workspace.rb, line 32
def editor
  return config['editor'] if config && config['editor']

  raise StandardError, 'Please set your editor'
end
list_notes(notebook) click to toggle source
# File lib/notes_cli/models/workspace.rb, line 18
def list_notes(notebook)
  NoteLister.new(notebook).call
end
open_notebook(notebook) click to toggle source
# File lib/notes_cli/models/workspace.rb, line 22
def open_notebook(notebook)
  system("#{editor} #{notebook_path(notebook)}")
end
switch(workspace) click to toggle source
# File lib/notes_cli/models/workspace.rb, line 26
def switch(workspace)
  return unless workspace_exists?(workspace) || create?('workspace')

  update_entry('workspace', workspace)
end
update_entry(key, value) click to toggle source
# File lib/notes_cli/models/workspace.rb, line 38
def update_entry(key, value)
  current_config = config
  current_config ? current_config[key] = value.strip.chomp : current_config = { key => value }
  File.open(NotesCli::CONFIG_PATH, 'w') { |file| file.truncate(0) }
  File.open(NotesCli::CONFIG_PATH, 'r+') do |f|
    YAML.dump(current_config, f)
  end
end