Class: MyTodo::Todo

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/my_todo.rb

Overview

Todo tasks using thor gem

Instance Method Summary collapse

Instance Method Details

#createObject



42
43
44
45
46
47
48
49
50
# File 'lib/my_todo.rb', line 42

def create
  begin
    say 'ToDo CREATED!'
    create_item(options)
    print_item
  rescue ActiveRecord::RecordInvalid => e
    say e.message
  end
end

#deleteObject



67
68
69
70
71
72
73
74
# File 'lib/my_todo.rb', line 67

def delete
  begin
    item.destroy!
    say 'ToDo DESTROYED!'
  rescue StandardError => e
    say e.message
  end
end

#listObject



34
35
36
37
# File 'lib/my_todo.rb', line 34

def list
  say "ToDos FOUND: #{all_items.count}"
  print_list
end

#noteObject



112
113
114
115
116
117
118
119
# File 'lib/my_todo.rb', line 112

def note
  begin
    item.notes.create(body: options[:body])
    print_notes
  rescue StandardError => e
    say e.message
  end
end

#notesObject



135
136
137
138
139
140
141
# File 'lib/my_todo.rb', line 135

def notes
  begin
    print_notes
  rescue StandardError => e
    say e.message
  end
end

#rm_noteObject



124
125
126
127
128
129
130
131
# File 'lib/my_todo.rb', line 124

def rm_note
  begin
    item.notes.where(id: options[:noteid]).first.destroy!
    print_list item.reload
  rescue StandardError => e
    say e.message
  end
end

#rm_tagObject



100
101
102
103
104
105
106
107
# File 'lib/my_todo.rb', line 100

def rm_tag
  begin
    item.tags.where(name: options[:tag]).first.destroy!
    print_list item.reload
  rescue StandardError => e
    say e.message
  end
end

#searchObject



78
79
80
81
82
83
# File 'lib/my_todo.rb', line 78

def search
  @items = Item.ransack(body_or_detailed_status_or_tags_name_or_notes_body_cont: options[:text]).result
  say "ToDos FOUND: #{@items.count}"
  say "Search based on ransack search: body_or_detailed_status_or_tags_name_or_notes_body_cont"
  print_search_results
end

#tagObject



88
89
90
91
92
93
94
95
# File 'lib/my_todo.rb', line 88

def tag
  begin
    item.tags.create!(name: options[:tag])
    print_list item.reload
  rescue StandardError => e
    say e.message
  end
end

#updateObject



55
56
57
58
59
60
61
62
63
# File 'lib/my_todo.rb', line 55

def update
  begin
    update_item(options)
    say 'ToDo UPDATED!'
    print_item
  rescue ActiveRecord::RecordInvalid => e
    say e.message
  end
end