Class: Hbtrack::RemoveCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/hbtrack/command/remove_command.rb

Instance Method Summary collapse

Methods inherited from Command

#help, #local_store

Constructor Details

#initialize(store_path, options) ⇒ RemoveCommand

Returns a new instance of RemoveCommand.



8
9
10
# File 'lib/hbtrack/command/remove_command.rb', line 8

def initialize(store_path, options)
  super(store_path, options)
end

Instance Method Details

#create_option_parserObject



17
18
19
20
21
# File 'lib/hbtrack/command/remove_command.rb', line 17

def create_option_parser
  OptionParser.new do |opts|
    opts.banner = 'Usage: hbtrack remove [<habit_name>]'
  end
end

#executeObject



12
13
14
15
# File 'lib/hbtrack/command/remove_command.rb', line 12

def execute
  return remove_from_db(@names, local_store)
  super
end

#feedback(names) ⇒ Object



23
24
25
# File 'lib/hbtrack/command/remove_command.rb', line 23

def feedback(names)
  Hbtrack::Util.blue("Remove #{names.join(',')}!")
end

#remove_from_db(names, store) ⇒ Object



27
28
29
30
31
32
# File 'lib/hbtrack/command/remove_command.rb', line 27

def remove_from_db(names, store)
  status = store.delete_habit(names)
  return ErrorHandler.raise_if_habit_error(names) if status == 0

  feedback(names)
end