Class: Rtasklib::TaskWarrior

Inherits:
Object
  • Object
show all
Includes:
Controller
Defined in:
lib/rtasklib.rb

Overview

To interact with the TaskWarrior database simply instantiate this with a path to the .task folder where data is stored. If left out it will look for a database in the default location `~/.task`

Optionally pass in a hash of taskrc options to override what is in your .taskrc on every command. By default `rtasklib` provides a set of sensible defaults:

These of course can be overridden with opts param as well

In general `rtasklib` is only feature complete on TaskWarrior installs 2.4 and greater and it will warn you if yours is lower or can't be determined, but will still allow you to interact with it. Proceed at your own risk.

Examples:

# Use the default path and overrides
tw = Rtasklib::TaskWarrior.new
# TaskWarrior is also available aliased as TW:
tw = Rtasklib::TW.new
# Custom path, in this case the test db in spec/
tw = Rtasklib::TW.new("./spec/data/.task")
# Custom override, in this case calling the gc everytime
# This will change id numbers whenever the task list changes
# By default this is off, but may have some performance implications.
tw = Rtasklib::TW.new(opts={gc: "on"})
DEFAULTS = {
  json_array:              'true',
  verbose:                 'nothing',
  gc:                      'off',
  confirmation:            'no',
  dependency_confirmation: 'no',
  exit_on_missing_db:      'yes', }

Constant Summary

DEFAULTS =

Sane defaults to override a base .taskrc

{
# Wrap export objects in an array? Disabling this will break Rtasklib
# functionality
json_array:              'true',
# Stop writing user friendly methods. Disabling this will break Rtasklib
# functionality
verbose:                 'nothing',
# Call the gc on every execution. This will change id numbers whenever the
# task list changes. By default this is off, but may have some
# performance implications.
gc:                      'off',
# Will ask for confirmation before we do anything TaskWarrior decides is
# dangerous. We handle most of these cases in Rtasklib.
confirmation:            'no',
dependency_confirmation: 'no',
# If it can't find a TaskWarrior db just exit.
exit_on_missing_db:      'yes', }
LOWEST_VERSION =

Lowest supported TaskWarrior version

Gem::Version.new('2.4.0')

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Controller

#add!, #all, #count, #create_uda!, #delete!, #done!, #get_rc, #get_uda_names, #get_udas, #get_version, #modify!, #some, #start!, #stop!, #sync!, #uda_exists?, #undo!, #update_config!

Constructor Details

- (TaskWarrior) initialize(data = "#{Dir.home}/.task", opts = {})

Returns a new instance of TaskWarrior

Parameters:

  • data (String, Pathname) (defaults to: "#{Dir.home}/.task")

    path to the .task database

  • opts (Hash) (defaults to: {})

    overrides to the .taskrc to run on each command



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rtasklib.rb', line 98

def initialize data="#{Dir.home}/.task", opts = {}
  # Check TaskWarrior version, and throw warning if unavailable
  begin
    @version = check_version
  rescue
    warn "Couldn't verify TaskWarrior's version"
  end

  @data_location = data
  override_h     = DEFAULTS.merge({data_location: data}).merge(opts)
  @override      = Taskrc.new(override_h, :hash)
  @override_a    = override.model_to_rc
  @taskrc        = get_rc
  @udas          = get_udas
  add_udas_to_model!(udas) unless udas.nil?
end

Instance Attribute Details

- (String) data_location (readonly)

Returns The file path that you passed in at initialization

Returns:

  • (String)

    The file path that you passed in at initialization



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rtasklib.rb', line 67

class TaskWarrior
  attr_reader :version, :data_location, :taskrc, :udas,
              :override, :override_a, :override_str

  include Controller

  # Sane defaults to override a base .taskrc
  DEFAULTS = {
    # Wrap export objects in an array? Disabling this will break Rtasklib
    # functionality
    json_array:              'true',
    # Stop writing user friendly methods. Disabling this will break Rtasklib
    # functionality
    verbose:                 'nothing',
    # Call the gc on every execution. This will change id numbers whenever the
    # task list changes. By default this is off, but may have some
    # performance implications.
    gc:                      'off',
    # Will ask for confirmation before we do anything TaskWarrior decides is
    # dangerous. We handle most of these cases in Rtasklib.
    confirmation:            'no',
    dependency_confirmation: 'no',
    # If it can't find a TaskWarrior db just exit.
    exit_on_missing_db:      'yes', }

  # Lowest supported TaskWarrior version
  LOWEST_VERSION = Gem::Version.new('2.4.0')

  # @param data [String, Pathname] path to the .task database
  # @param opts [Hash] overrides to the .taskrc to run on each command
  # @api public
  def initialize data="#{Dir.home}/.task", opts = {}
    # Check TaskWarrior version, and throw warning if unavailable
    begin
      @version = check_version
    rescue
      warn "Couldn't verify TaskWarrior's version"
    end

    @data_location = data
    override_h     = DEFAULTS.merge({data_location: data}).merge(opts)
    @override      = Taskrc.new(override_h, :hash)
    @override_a    = override.model_to_rc
    @taskrc        = get_rc
    @udas          = get_udas
    add_udas_to_model!(udas) unless udas.nil?
  end

  # Check the state of the TaskWarrior install. Either pass a Gem::Version
  # representation passed to the version param or call with no args for
  # it to make a call to the shell to figure that out itself.
  #
  # @param version [Gem::Version, nil] version to check
  # @return [Gem::Version]
  # @api public
  def check_version version=nil
    version = get_version if version.nil?
    if version < LOWEST_VERSION
      warn "The current TaskWarrior version, #{version}, is untested"
    end
    version
  end
end

- (Rtasklib::Taskrc) override (readonly)

Returns The options to override the default .taskrc

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rtasklib.rb', line 67

class TaskWarrior
  attr_reader :version, :data_location, :taskrc, :udas,
              :override, :override_a, :override_str

  include Controller

  # Sane defaults to override a base .taskrc
  DEFAULTS = {
    # Wrap export objects in an array? Disabling this will break Rtasklib
    # functionality
    json_array:              'true',
    # Stop writing user friendly methods. Disabling this will break Rtasklib
    # functionality
    verbose:                 'nothing',
    # Call the gc on every execution. This will change id numbers whenever the
    # task list changes. By default this is off, but may have some
    # performance implications.
    gc:                      'off',
    # Will ask for confirmation before we do anything TaskWarrior decides is
    # dangerous. We handle most of these cases in Rtasklib.
    confirmation:            'no',
    dependency_confirmation: 'no',
    # If it can't find a TaskWarrior db just exit.
    exit_on_missing_db:      'yes', }

  # Lowest supported TaskWarrior version
  LOWEST_VERSION = Gem::Version.new('2.4.0')

  # @param data [String, Pathname] path to the .task database
  # @param opts [Hash] overrides to the .taskrc to run on each command
  # @api public
  def initialize data="#{Dir.home}/.task", opts = {}
    # Check TaskWarrior version, and throw warning if unavailable
    begin
      @version = check_version
    rescue
      warn "Couldn't verify TaskWarrior's version"
    end

    @data_location = data
    override_h     = DEFAULTS.merge({data_location: data}).merge(opts)
    @override      = Taskrc.new(override_h, :hash)
    @override_a    = override.model_to_rc
    @taskrc        = get_rc
    @udas          = get_udas
    add_udas_to_model!(udas) unless udas.nil?
  end

  # Check the state of the TaskWarrior install. Either pass a Gem::Version
  # representation passed to the version param or call with no args for
  # it to make a call to the shell to figure that out itself.
  #
  # @param version [Gem::Version, nil] version to check
  # @return [Gem::Version]
  # @api public
  def check_version version=nil
    version = get_version if version.nil?
    if version < LOWEST_VERSION
      warn "The current TaskWarrior version, #{version}, is untested"
    end
    version
  end
end

- (Array) override_a (readonly)

Returns override in array form, useful for passing to shell

Returns:

  • (Array)

    override in array form, useful for passing to shell



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rtasklib.rb', line 67

class TaskWarrior
  attr_reader :version, :data_location, :taskrc, :udas,
              :override, :override_a, :override_str

  include Controller

  # Sane defaults to override a base .taskrc
  DEFAULTS = {
    # Wrap export objects in an array? Disabling this will break Rtasklib
    # functionality
    json_array:              'true',
    # Stop writing user friendly methods. Disabling this will break Rtasklib
    # functionality
    verbose:                 'nothing',
    # Call the gc on every execution. This will change id numbers whenever the
    # task list changes. By default this is off, but may have some
    # performance implications.
    gc:                      'off',
    # Will ask for confirmation before we do anything TaskWarrior decides is
    # dangerous. We handle most of these cases in Rtasklib.
    confirmation:            'no',
    dependency_confirmation: 'no',
    # If it can't find a TaskWarrior db just exit.
    exit_on_missing_db:      'yes', }

  # Lowest supported TaskWarrior version
  LOWEST_VERSION = Gem::Version.new('2.4.0')

  # @param data [String, Pathname] path to the .task database
  # @param opts [Hash] overrides to the .taskrc to run on each command
  # @api public
  def initialize data="#{Dir.home}/.task", opts = {}
    # Check TaskWarrior version, and throw warning if unavailable
    begin
      @version = check_version
    rescue
      warn "Couldn't verify TaskWarrior's version"
    end

    @data_location = data
    override_h     = DEFAULTS.merge({data_location: data}).merge(opts)
    @override      = Taskrc.new(override_h, :hash)
    @override_a    = override.model_to_rc
    @taskrc        = get_rc
    @udas          = get_udas
    add_udas_to_model!(udas) unless udas.nil?
  end

  # Check the state of the TaskWarrior install. Either pass a Gem::Version
  # representation passed to the version param or call with no args for
  # it to make a call to the shell to figure that out itself.
  #
  # @param version [Gem::Version, nil] version to check
  # @return [Gem::Version]
  # @api public
  def check_version version=nil
    version = get_version if version.nil?
    if version < LOWEST_VERSION
      warn "The current TaskWarrior version, #{version}, is untested"
    end
    version
  end
end

- (String) override_str (readonly)

Returns override in string form, useful for passing to shell

Returns:

  • (String)

    override in string form, useful for passing to shell



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rtasklib.rb', line 67

class TaskWarrior
  attr_reader :version, :data_location, :taskrc, :udas,
              :override, :override_a, :override_str

  include Controller

  # Sane defaults to override a base .taskrc
  DEFAULTS = {
    # Wrap export objects in an array? Disabling this will break Rtasklib
    # functionality
    json_array:              'true',
    # Stop writing user friendly methods. Disabling this will break Rtasklib
    # functionality
    verbose:                 'nothing',
    # Call the gc on every execution. This will change id numbers whenever the
    # task list changes. By default this is off, but may have some
    # performance implications.
    gc:                      'off',
    # Will ask for confirmation before we do anything TaskWarrior decides is
    # dangerous. We handle most of these cases in Rtasklib.
    confirmation:            'no',
    dependency_confirmation: 'no',
    # If it can't find a TaskWarrior db just exit.
    exit_on_missing_db:      'yes', }

  # Lowest supported TaskWarrior version
  LOWEST_VERSION = Gem::Version.new('2.4.0')

  # @param data [String, Pathname] path to the .task database
  # @param opts [Hash] overrides to the .taskrc to run on each command
  # @api public
  def initialize data="#{Dir.home}/.task", opts = {}
    # Check TaskWarrior version, and throw warning if unavailable
    begin
      @version = check_version
    rescue
      warn "Couldn't verify TaskWarrior's version"
    end

    @data_location = data
    override_h     = DEFAULTS.merge({data_location: data}).merge(opts)
    @override      = Taskrc.new(override_h, :hash)
    @override_a    = override.model_to_rc
    @taskrc        = get_rc
    @udas          = get_udas
    add_udas_to_model!(udas) unless udas.nil?
  end

  # Check the state of the TaskWarrior install. Either pass a Gem::Version
  # representation passed to the version param or call with no args for
  # it to make a call to the shell to figure that out itself.
  #
  # @param version [Gem::Version, nil] version to check
  # @return [Gem::Version]
  # @api public
  def check_version version=nil
    version = get_version if version.nil?
    if version < LOWEST_VERSION
      warn "The current TaskWarrior version, #{version}, is untested"
    end
    version
  end
end

- (Rtasklib::Taskrc) taskrc (readonly)

Returns Your current TaskWarrior configuration

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rtasklib.rb', line 67

class TaskWarrior
  attr_reader :version, :data_location, :taskrc, :udas,
              :override, :override_a, :override_str

  include Controller

  # Sane defaults to override a base .taskrc
  DEFAULTS = {
    # Wrap export objects in an array? Disabling this will break Rtasklib
    # functionality
    json_array:              'true',
    # Stop writing user friendly methods. Disabling this will break Rtasklib
    # functionality
    verbose:                 'nothing',
    # Call the gc on every execution. This will change id numbers whenever the
    # task list changes. By default this is off, but may have some
    # performance implications.
    gc:                      'off',
    # Will ask for confirmation before we do anything TaskWarrior decides is
    # dangerous. We handle most of these cases in Rtasklib.
    confirmation:            'no',
    dependency_confirmation: 'no',
    # If it can't find a TaskWarrior db just exit.
    exit_on_missing_db:      'yes', }

  # Lowest supported TaskWarrior version
  LOWEST_VERSION = Gem::Version.new('2.4.0')

  # @param data [String, Pathname] path to the .task database
  # @param opts [Hash] overrides to the .taskrc to run on each command
  # @api public
  def initialize data="#{Dir.home}/.task", opts = {}
    # Check TaskWarrior version, and throw warning if unavailable
    begin
      @version = check_version
    rescue
      warn "Couldn't verify TaskWarrior's version"
    end

    @data_location = data
    override_h     = DEFAULTS.merge({data_location: data}).merge(opts)
    @override      = Taskrc.new(override_h, :hash)
    @override_a    = override.model_to_rc
    @taskrc        = get_rc
    @udas          = get_udas
    add_udas_to_model!(udas) unless udas.nil?
  end

  # Check the state of the TaskWarrior install. Either pass a Gem::Version
  # representation passed to the version param or call with no args for
  # it to make a call to the shell to figure that out itself.
  #
  # @param version [Gem::Version, nil] version to check
  # @return [Gem::Version]
  # @api public
  def check_version version=nil
    version = get_version if version.nil?
    if version < LOWEST_VERSION
      warn "The current TaskWarrior version, #{version}, is untested"
    end
    version
  end
end

- (Hash{Symbol=>Hash}) udas (readonly)

Returns Currently configured User Defined Attributes

Returns:

  • (Hash{Symbol=>Hash})

    Currently configured User Defined Attributes



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rtasklib.rb', line 67

class TaskWarrior
  attr_reader :version, :data_location, :taskrc, :udas,
              :override, :override_a, :override_str

  include Controller

  # Sane defaults to override a base .taskrc
  DEFAULTS = {
    # Wrap export objects in an array? Disabling this will break Rtasklib
    # functionality
    json_array:              'true',
    # Stop writing user friendly methods. Disabling this will break Rtasklib
    # functionality
    verbose:                 'nothing',
    # Call the gc on every execution. This will change id numbers whenever the
    # task list changes. By default this is off, but may have some
    # performance implications.
    gc:                      'off',
    # Will ask for confirmation before we do anything TaskWarrior decides is
    # dangerous. We handle most of these cases in Rtasklib.
    confirmation:            'no',
    dependency_confirmation: 'no',
    # If it can't find a TaskWarrior db just exit.
    exit_on_missing_db:      'yes', }

  # Lowest supported TaskWarrior version
  LOWEST_VERSION = Gem::Version.new('2.4.0')

  # @param data [String, Pathname] path to the .task database
  # @param opts [Hash] overrides to the .taskrc to run on each command
  # @api public
  def initialize data="#{Dir.home}/.task", opts = {}
    # Check TaskWarrior version, and throw warning if unavailable
    begin
      @version = check_version
    rescue
      warn "Couldn't verify TaskWarrior's version"
    end

    @data_location = data
    override_h     = DEFAULTS.merge({data_location: data}).merge(opts)
    @override      = Taskrc.new(override_h, :hash)
    @override_a    = override.model_to_rc
    @taskrc        = get_rc
    @udas          = get_udas
    add_udas_to_model!(udas) unless udas.nil?
  end

  # Check the state of the TaskWarrior install. Either pass a Gem::Version
  # representation passed to the version param or call with no args for
  # it to make a call to the shell to figure that out itself.
  #
  # @param version [Gem::Version, nil] version to check
  # @return [Gem::Version]
  # @api public
  def check_version version=nil
    version = get_version if version.nil?
    if version < LOWEST_VERSION
      warn "The current TaskWarrior version, #{version}, is untested"
    end
    version
  end
end

- (Gem::Version) version (readonly)

Returns The version of the current TaskWarrior install

Returns:

  • (Gem::Version)

    The version of the current TaskWarrior install



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rtasklib.rb', line 67

class TaskWarrior
  attr_reader :version, :data_location, :taskrc, :udas,
              :override, :override_a, :override_str

  include Controller

  # Sane defaults to override a base .taskrc
  DEFAULTS = {
    # Wrap export objects in an array? Disabling this will break Rtasklib
    # functionality
    json_array:              'true',
    # Stop writing user friendly methods. Disabling this will break Rtasklib
    # functionality
    verbose:                 'nothing',
    # Call the gc on every execution. This will change id numbers whenever the
    # task list changes. By default this is off, but may have some
    # performance implications.
    gc:                      'off',
    # Will ask for confirmation before we do anything TaskWarrior decides is
    # dangerous. We handle most of these cases in Rtasklib.
    confirmation:            'no',
    dependency_confirmation: 'no',
    # If it can't find a TaskWarrior db just exit.
    exit_on_missing_db:      'yes', }

  # Lowest supported TaskWarrior version
  LOWEST_VERSION = Gem::Version.new('2.4.0')

  # @param data [String, Pathname] path to the .task database
  # @param opts [Hash] overrides to the .taskrc to run on each command
  # @api public
  def initialize data="#{Dir.home}/.task", opts = {}
    # Check TaskWarrior version, and throw warning if unavailable
    begin
      @version = check_version
    rescue
      warn "Couldn't verify TaskWarrior's version"
    end

    @data_location = data
    override_h     = DEFAULTS.merge({data_location: data}).merge(opts)
    @override      = Taskrc.new(override_h, :hash)
    @override_a    = override.model_to_rc
    @taskrc        = get_rc
    @udas          = get_udas
    add_udas_to_model!(udas) unless udas.nil?
  end

  # Check the state of the TaskWarrior install. Either pass a Gem::Version
  # representation passed to the version param or call with no args for
  # it to make a call to the shell to figure that out itself.
  #
  # @param version [Gem::Version, nil] version to check
  # @return [Gem::Version]
  # @api public
  def check_version version=nil
    version = get_version if version.nil?
    if version < LOWEST_VERSION
      warn "The current TaskWarrior version, #{version}, is untested"
    end
    version
  end
end

Instance Method Details

- (Gem::Version) check_version(version = nil)

Check the state of the TaskWarrior install. Either pass a Gem::Version representation passed to the version param or call with no args for it to make a call to the shell to figure that out itself.

Parameters:

  • version (Gem::Version, nil) (defaults to: nil)

    version to check

Returns:

  • (Gem::Version)


122
123
124
125
126
127
128
# File 'lib/rtasklib.rb', line 122

def check_version version=nil
  version = get_version if version.nil?
  if version < LOWEST_VERSION
    warn "The current TaskWarrior version, #{version}, is untested"
  end
  version
end