Sha256: 84ebd1db2b32acd112817553baedc81d9bbd00dc7388d432dd7cf67ab2fed7d8
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
require 'shellwords' module TaskwarriorWeb::CommandBuilder module Base TASK_COMMANDS = { :add => 'add', :query => '_query', :count => 'count', :complete => ':id done', :projects => '_projects', :tags => '_tags' } def build unless @command_string task_command substitute_parts if @command_string =~ /:id/ end parse_params @built = "#{@command_string}#{@params}" end def task_command if TASK_COMMANDS.has_key?(@command.to_sym) @command_string = TASK_COMMANDS[@command.to_sym].clone else raise InvalidCommandError end end def substitute_parts if @id @command_string.gsub!(':id', "uuid:#{@id.to_s}") return self else raise TaskwarriorWeb::CommandBuilder::MissingTaskIDError end end def parse_params string = '' string << %Q( #{@params.delete(:description).shellescape}) if @params.has_key?(:description) if @params.has_key?(:tags) tags = @params.delete(:tags) tag_indicator = TaskwarriorWeb::Config.property('tag.indicator') || '+' tags.each { |tag| string << %Q( #{tag_indicator}#{tag.to_s.shellescape}) } end @params.each do |attr, value| if value.respond_to? :each value.each { |val| string << %Q( #{attr.to_s}:\\"#{val.to_s.shellescape}\\") } else string << %Q( #{attr.to_s}:\\"#{value.to_s.shellescape}\\") end end @params = string return self end end class InvalidCommandError < Exception; end class MissingTaskIDError < Exception; end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
taskwarrior-web-1.0.6 | lib/taskwarrior-web/command_builders/base.rb |