Class: Workspace
Instance Method Summary
collapse
#config, #create?, #current_workspace, #notebook_exists?, #notebook_path, #notes_folder, #workspace_exists?, #workspace_path
Constructor Details
Returns a new instance of Workspace.
6
7
8
|
# File 'lib/notes_cli/models/workspace.rb', line 6
def initialize
FileUtils.touch(NotesCli::CONFIG_PATH) unless File.file?(NotesCli::CONFIG_PATH)
end
|
Instance Method Details
#create_note(notebook, title) ⇒ Object
10
11
12
|
# 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) ⇒ Object
14
15
16
|
# 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 ⇒ Object
32
33
34
35
36
|
# 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) ⇒ Object
18
19
20
|
# File 'lib/notes_cli/models/workspace.rb', line 18
def list_notes(notebook)
NoteLister.new(notebook).call
end
|
#open_notebook(notebook) ⇒ Object
22
23
24
|
# File 'lib/notes_cli/models/workspace.rb', line 22
def open_notebook(notebook)
system("#{editor} #{notebook_path(notebook)}")
end
|
#switch(workspace) ⇒ Object
26
27
28
29
30
|
# 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) ⇒ Object
38
39
40
41
42
43
44
45
|
# 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
|