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
82 83 84 85 86 87 88 89 90 |
# File 'lib/my_todo.rb', line 82 def create begin say 'ToDo CREATED!' create_item() output @item rescue ActiveRecord::RecordInvalid => e say e. end end |
#delete(id) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/my_todo.rb', line 108 def delete(id) begin item = Item.find_by_id(id) output item item.destroy! say 'ToDo DESTROYED!' rescue StandardError => e say e. end end |
#list(status = nil) ⇒ Object
71 72 73 74 75 |
# File 'lib/my_todo.rb', line 71 def list(status=nil) items = all_items(status) say "ToDos FOUND: #{items.count}" items.each {|item| output(item)} end |
#note ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/my_todo.rb', line 154 def note begin item.notes.create(body: [:body]) output item.reload rescue StandardError => e say e. end end |
#rm_note ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/my_todo.rb', line 166 def rm_note begin item.notes.where(id: [:noteid]).first.destroy! output item.reload rescue StandardError => e say e. end end |
#rm_tag ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'lib/my_todo.rb', line 142 def rm_tag begin item..where(name: [:tag]).first.destroy! output item.reload rescue StandardError => e say e. end end |
#search(text) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/my_todo.rb', line 120 def search(text) items = Item.ransack(body_or_detailed_status_or_tags_name_or_notes_body_cont: text).result say "ToDos FOUND: #{items.count}" say "Search based on ransack search: body_or_detailed_status_or_tags_name_or_notes_body_cont" items.each {|item| output item} end |
#tag ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/my_todo.rb', line 130 def tag begin item..create!(name: [:tag]) output item.reload rescue StandardError => e say e. end end |
#update ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/my_todo.rb', line 97 def update begin update_item() say 'ToDo UPDATED!' output item rescue ActiveRecord::RecordInvalid => e say e. end end |