Class: MyTodo::Todo
Overview
Todo tasks using thor gem
Instance Method Summary collapse
- #create ⇒ Object
- #delete(id) ⇒ Object
- #list(status = nil) ⇒ Object
- #note ⇒ Object
- #rm_note ⇒ Object
- #rm_tag ⇒ Object
- #search(text) ⇒ Object
- #tag ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/my_todo.rb', line 54 def create begin item = Item.create!(.except(:tags)) [:tags].split(' ').each{|tag| item..create(name: tag) } say 'ToDo CREATED!' output item rescue ActiveRecord::RecordInvalid => e say e. end end |
#delete(id) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/my_todo.rb', line 81 def delete(id) begin item = Item.find_by_id(id) output item item.destroy! say 'ToDo DESTROYED!' rescue Exception => e say e. end end |
#list(status = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/my_todo.rb', line 35 def list(status=nil) items = case status when 'all' Item.all when 'done' Item.where(done: true) else Item.where(done: false) end say "ToDos FOUND: #{items.count}" items.each {|item| output(item)} end |
#note ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/my_todo.rb', line 125 def note begin item.notes.create(body: [:body]) output item.reload rescue Exception => e say e. end end |
#rm_note ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/my_todo.rb', line 137 def rm_note begin item.notes.where(id: [:noteid]).first.destroy! output item.reload rescue Exception => e say e. end end |
#rm_tag ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/my_todo.rb', line 113 def rm_tag begin item..where(name: [:tag]).first.destroy! output item.reload rescue Exception => e say e. end end |
#search(text) ⇒ Object
93 94 95 96 97 |
# File 'lib/my_todo.rb', line 93 def search(text) items = Item.ransack(body_or_tags_name_or_notes_body_cont: text).result say "ToDos FOUND: #{items.count}" items.each {|item| output item} end |
#tag ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/my_todo.rb', line 102 def tag begin item..create!(name: [:tag]) rescue Exception => e say e. end end |
#update ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/my_todo.rb', line 70 def update begin item.update!() say 'ToDo UPDATED!' output item rescue ActiveRecord::RecordInvalid => e say e. end end |