Module: TaskwarriorWeb::CommandBuilder::Base

Included in:
V1, V2
Defined in:
lib/taskwarrior-web/services/builder/base.rb

Constant Summary collapse

TASK_COMMANDS =
{
  :add => 'add',
  :update => TaskwarriorWeb::Config.version.major >= 2 ? ':id mod' : nil,
  :delete => 'rc.confirmation=no :id delete',
  :query => TaskwarriorWeb::Config.version == '1.9.4' ? '_query' : 'export',
  :complete => ':id done',
  :annotate => ':id annotate',
  :denotate => ':id denotate',
  :projects => '_projects',
  :tags => '_tags',
  :sync => 'sync'
}

Instance Method Summary collapse

Instance Method Details

#buildObject



18
19
20
21
22
23
24
25
# File 'lib/taskwarrior-web/services/builder/base.rb', line 18

def build
  unless @command_string
    task_command
    substitute_parts if @command_string =~ /:id/
  end
  parse_params
  @built = "#{@command_string}#{@params}"
end

#parse_paramsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/taskwarrior-web/services/builder/base.rb', line 44

def parse_params
  string = ''
  string << %( #{@params.delete(:description).shellescape}) if @params.has_key?(:description)

  if tags = @params.delete(:tags)
    tag_indicator = TaskwarriorWeb::Config.property('tag.indicator') || '+'
    tags.each { |tag| string << %( #{tag_indicator}#{tag.to_s.shellescape}) }
  end

  if tags = @params.delete(:remove_tags)
    tags.each { |tag| string << %( -#{tag.to_s.shellescape}) } 
  end

  @params.each do |attr, value|
    if @command != :update or attr != :uuid
      if value.respond_to? :each
        value.each { |val| string << %( #{attr.to_s}:\\"#{val.to_s.shellescape}\\") }
      else
        string << %( #{attr.to_s}:\\"#{value.to_s.shellescape}\\")
      end
    end
  end

  @params = string
  return self
end

#substitute_partsObject



36
37
38
39
40
41
42
# File 'lib/taskwarrior-web/services/builder/base.rb', line 36

def substitute_parts
  if @id
    @command_string.gsub!(':id', "uuid:#{@id.to_s}")
    return self
  end
  raise TaskwarriorWeb::CommandBuilder::MissingTaskIDError
end

#task_commandObject



27
28
29
30
31
32
33
34
# File 'lib/taskwarrior-web/services/builder/base.rb', line 27

def task_command
  if TASK_COMMANDS[@command.to_sym]
    @command_string = TASK_COMMANDS[@command.to_sym].clone
    return self
  else
    raise TaskwarriorWeb::CommandBuilder::InvalidCommandError
  end
end