Module: MyTodoActions

Defined in:
lib/my_todo/modules/my_todo_actions.rb

Instance Method Summary collapse

Instance Method Details

#ask_statusObject



2
3
4
5
# File 'lib/my_todo/modules/my_todo_actions.rb', line 2

def ask_status
  list_statuses
  @status = ask("Choose a status for item", default: set_default_status)
end

#assign_detailed_statusObject



21
22
23
24
# File 'lib/my_todo/modules/my_todo_actions.rb', line 21

def assign_detailed_status
  ask_status
  @item.write_attribute(:detailed_status, detailed_statuses[@status.to_i])
end

#create_item(options) ⇒ Object



7
8
9
10
11
12
# File 'lib/my_todo/modules/my_todo_actions.rb', line 7

def create_item(options)
  @item = Item.new(options.except(:tags))
  assign_detailed_status
  @item.save!
  set_tags
end

#set_default_statusObject



30
31
32
# File 'lib/my_todo/modules/my_todo_actions.rb', line 30

def set_default_status
  @item.detailed_status.nil? ? 1 : detailed_statuses.index(@item.detailed_status)
end

#set_tagsObject



26
27
28
# File 'lib/my_todo/modules/my_todo_actions.rb', line 26

def set_tags
  options[:tags].split(' ').each{|tag| @item.tags.create(name: tag) } if options[:tags]
end

#update_item(options) ⇒ Object



14
15
16
17
18
19
# File 'lib/my_todo/modules/my_todo_actions.rb', line 14

def update_item(options)
  item.assign_attributes(options)
  @item = item #Find a better way!!!!
  assign_detailed_status
  item.save!
end