class ToDo::Session

Creates or reopens a to-do file for the given date.

Constants

TEMPLATE

TODO: Add support for custom templates

Attributes

context[R]

Public Class Methods

new(context) click to toggle source
# File lib/session.rb, line 22
def initialize(context)
  @context = context
  @date = context.options.date

  Dir.mkdir(context.dir_path) unless Dir[context.dir_path].any?
  prepare_todo_file
end

Public Instance Methods

start() click to toggle source
# File lib/session.rb, line 30
def start
  exit_and_set_editor unless system("command -v #{context.editor}", out: ['/dev/null'])
  system("#{context.editor} #{context.file_path}")
end

Private Instance Methods

exit_and_set_editor() click to toggle source
# File lib/session.rb, line 37
def exit_and_set_editor
  puts "#{context.editor} not found" if context.editor
  puts "Please set an editor to use with `todo -e EDITOR'. Check `todo -h' for more info."
  exit 1
end
prepare_todo_file() click to toggle source
# File lib/session.rb, line 43
def prepare_todo_file
  return if Dir[context.file_path].any?

  File.open(context.file_path, 'w') do |f|
    f.puts TEMPLATE.result(self.binding)
  end
end