class Wutang::Cli

Constants

PUBLIC_COMMANDS

Attributes

args[R]
command[R]
wutang[R]

Public Class Methods

new(wutang) click to toggle source
# File lib/wutang/cli.rb, line 6
def initialize(wutang)
  @command = ARGV.shift.to_s.to_sym
  @args    = ARGV
  @wutang  = wutang
end

Public Instance Methods

attributes() click to toggle source
# File lib/wutang/cli.rb, line 43
def attributes
  {}.tap do|hash|
    args.each do |arg|
      key, value       = arg.split(':')
      hash[key.to_sym] = value
    end
  end
end
create() click to toggle source
# File lib/wutang/cli.rb, line 20
def create
  entry = wutang.create attributes
  puts "Created #{entry}"
end
handle() click to toggle source
# File lib/wutang/cli.rb, line 12
def handle
  if PUBLIC_COMMANDS.include?(command)
    send(command)
  else
    puts "Unknown command #{command}"
  end
end
list() click to toggle source
# File lib/wutang/cli.rb, line 39
def list
  puts wutang.entries
end
update() click to toggle source
# File lib/wutang/cli.rb, line 25
def update
  if entry = wutang.find(args.shift)
    wutang.update entry, attributes
    puts "Entry updated with the following changes: #{attributes}"
  else
    puts "Entry not found"
  end
end