Module: Rtasklib::Controller

Extended by:
Controller
Included in:
Controller, TaskWarrior
Defined in:
lib/rtasklib/controller.rb

Instance Method Summary collapse

Instance Method Details

#add!Object



26
27
# File 'lib/rtasklib/controller.rb', line 26

def add!
end

#allArray<Models::TaskModel>

Retrieves the current task list from the TW database

Returns:

API:

  • public



13
14
15
16
17
18
19
20
21
# File 'lib/rtasklib/controller.rb', line 13

def all
  all = []
  Execute.task_popen3(*@override_a, "export") do |i, o, e, t|
    all = MultiJson.load(o.read).map do |x|
      Rtasklib::Models::TaskModel.new(x)
    end
  end
  all
end

#arbitrary_attr(attr, depth: 1) ⇒ Object

Returns part of attribute at a given depth



64
65
66
# File 'lib/rtasklib/controller.rb', line 64

def arbitrary_attr attr, depth: 1
  attr.to_s.split("_")[depth]
end

#check_uda(uda_name) ⇒ Boolean

Checks if a given uda exists in the current task database

Parameters:

  • the uda name to check for

Returns:

  • whether it matches or not

API:

  • public



90
91
92
93
94
95
96
# File 'lib/rtasklib/controller.rb', line 90

def check_uda uda_name
  if get_udas.any? { |uda| uda == uda_name }
    true
  else
    false
  end
end

#create_uda(name, type: "string", label: nil, values: nil, default: nil, urgency: nil) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rtasklib/controller.rb', line 98

def create_uda name, type: "string", label: nil, values: nil,
               default: nil, urgency: nil
  label = name if label.nil?
  p name, label, values, default, urgency

  update_config "uda.#{name}.type",  type
  update_config "uda.#{name}.label", label
  update_config "uda.#{name}.values",  values unless values.nil?
  update_config "uda.#{name}.default", default unless default.nil?
  update_config "uda.#{name}.urgency", urgency unless urgency.nil?
end

#filter(ids: nil, tags: nil, query: nil) ⇒ Object



23
24
# File 'lib/rtasklib/controller.rb', line 23

def filter ids: nil, tags: nil, query: nil
end

#get_rcObject



110
111
112
113
114
115
116
# File 'lib/rtasklib/controller.rb', line 110

def get_rc
  res = []
  Execute.task_popen3(*@override_a, "_show") do |i, o, e, t|
    res = o.read.each_line.map { |l| l.chomp }
  end
  Taskrc.new(res, :array)
end

#get_uda_namesArray<String>

Retrieve an array of the uda names

Returns:

API:

  • public



79
80
81
82
83
# File 'lib/rtasklib/controller.rb', line 79

def get_uda_names
  Execute.task_popen3(*@override_a, "_udas") do |i, o, e, t|
    return o.read.each_line.map { |l| l.chomp }
  end
end

#get_udasObject

Retrieves an array of hashes with info about the udas currently available



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rtasklib/controller.rb', line 42

def get_udas
  taskrc.config.attributes
    .select { |attr, val| uda_attr? attr }
    .sort
    .chunk  { |attr, val| arbitrary_attr attr }
    .map do |attr, arr|
      uda = arr.map do |pair|
        key = deep_attr(pair[0])
        val = pair[1]
        [key, val]
      end
      {attr.to_sym => Hash[uda]}
    end
end

#get_versionObject



118
119
120
121
122
123
124
# File 'lib/rtasklib/controller.rb', line 118

def get_version
  version = nil
  Execute.task_popen3(*@override_a, "_version") do |i, o, e, t|
    version = to_gem_version(o.read.chomp)
  end
  version
end

#undo!Object

def modify! attr:, val:, ids: nil, tags: nil, query: nil end



32
33
# File 'lib/rtasklib/controller.rb', line 32

def undo!
end

#update_config!(attr, val) ⇒ Object



35
36
37
38
39
# File 'lib/rtasklib/controller.rb', line 35

def update_config! attr, val
  Execute.task_popen3(*override_a, "config #{attr} #{val}") do |i, o, e, t|
    return t.value
  end
end