Skip to content

Commit

Permalink
Move version check up, better uda handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dropofwill committed May 15, 2015
1 parent b3fb393 commit dfa2575
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
13 changes: 6 additions & 7 deletions lib/rtasklib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class TaskWarrior
LOWEST_VERSION = Gem::Version.new('2.4.0')

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

@data_location = data
override_h = DEFAULTS.merge({data_location: data}).merge(opts)
Expand All @@ -33,13 +39,6 @@ def initialize data="#{Dir.home}/.task", opts = {}
@taskrc = get_rc
@udas = get_udas
add_uda_to_model udas

# Check TaskWarrior version, and throw warning if unavailable
begin
@version = check_version(get_version())
rescue
warn "Couldn't verify TaskWarrior's version"
end
end

def check_version version
Expand Down
18 changes: 11 additions & 7 deletions lib/rtasklib/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,22 @@ def update_config! attr, val
end
end

# Retrieves an array of hashes with info about the udas currently available
# Retrieves a hash of hashes with info about the udas currently available
def get_udas
udas = {}
taskrc.config.attributes
.select { |attr, val| uda_attr? attr }
.sort
.chunk { |attr, val| arbitrary_attr attr }
.map do |attr, arr|
.each do |attr, arr|
uda = arr.map do |pair|
key = deep_attr(pair[0])
val = pair[1]
[key, val]
end
{attr.to_sym => Hash[uda]}
udas[attr.to_sym] = Hash[uda]
end
return udas
end

# Is a given attribute dealing with udas?
Expand All @@ -105,10 +107,12 @@ def deep_attr attr, depth: 2
end
private :deep_attr

def add_uda_to_model uda_hash, model=Rtasklib::Models::TaskModel
uda_hash.each do |uda|
uda.each do |attr, val|
model.attribute attr, String
#
def add_uda_to_model uda_hash, type=nil, model=Models::TaskModel
uda_hash.each do |attr, val|
val.each do |k, v|
type = Helpers.determine_type(v) if type.nil?
model.attribute attr, type
end
end
end
Expand Down
8 changes: 0 additions & 8 deletions lib/rtasklib/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,5 @@ def handle_response stderr, thread
exit(-1)
end
end

# Filters should be a list of values
# Ranges interpreted as ids
# 1...5 : "1-5"
# 1..5 : "1-4"
# 1 : "1"
# and joined with ","
# [1...5, 8, 9] : "1-5,8,9"
end
end

0 comments on commit dfa2575

Please sign in to comment.