Class: Worque::Command::Todo::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/worque/command/todo/action.rb

Constant Summary collapse

FILE_PATH_FORMAT =
"%<path>s/notes-%<date>s.md".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Action

Returns a new instance of Action.



11
12
13
14
# File 'lib/worque/command/todo/action.rb', line 11

def initialize(options)
  @options = options
  validate_options!
end

Class Method Details

.run(options) ⇒ Object



36
37
38
# File 'lib/worque/command/todo/action.rb', line 36

def run(options)
  new(Worque::Command::Todo::Options.new(options)).call()
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/worque/command/todo/action.rb', line 16

def call
  Worque::Utils::Command.mkdir(options.path)

  notes_file_path = filename(date_for).tap do |f|
    Worque::Utils::Command.touch f
  end

  if options.template_path && File.read(notes_file_path) == ""
    template = File.read(File.expand_path(options.template_path))
    Worque::Utils::Command.append_text(notes_file_path, template)
  end

  if options.append_task
    Worque::Utils::Command.append_text(notes_file_path, options.append_task)
  end

  notes_file_path
end