lib/nin/todo.rb in nin-1.2.0 vs lib/nin/todo.rb in nin-1.3.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'timeout'
+
module Nin
class Todo
attr_accessor :items
attr_reader :store
@@ -69,13 +71,17 @@
@store.write(to_hash)
end
def archive(*ids)
- ids.each do |id|
- item = find_by_id(id.to_i)
- item.toggle_archived!
+ unless @options[:completed_only]
+ ids.each do |id|
+ item = find_by_id(id.to_i)
+ item.toggle_archived!
+ end
+ else
+ completed_unarchived_items.each(&:toggle_archived!)
end
@store.write(to_hash)
end
@@ -106,12 +112,19 @@
end
def sync(op, store_write = false, params = {})
return unless @integration_syncrhonizer
- @integration_syncrhonizer.sync(op, params)
- reset_item_indices! if store_write
+ begin
+ Timeout::timeout(@integration_syncrhonizer.timeout_interval) {
+ @integration_syncrhonizer.sync(op, params)
+ reset_item_indices! if store_write
+ }
+ rescue Timeout::Error
+ puts 'Syncing timed out. Showing local items...'
+ puts
+ end
end
def fork_sync(op, store_write = false, params = {})
return unless @integration_syncrhonizer
@@ -152,9 +165,13 @@
@items.where(:archived?, true)
end
def unarchived_items
@items.where(:archived?, false)
+ end
+
+ def completed_unarchived_items
+ unarchived_items.where(:completed, true)
end
def find_by_id(id)
found_item = @items.find_by(:id, id)