Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
markburns committed Mar 18, 2012
1 parent 9f4bacd commit 648f0e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
27 changes: 14 additions & 13 deletions lib/kaboom/command.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ def delegate(command, major, minor)
return random(major) if command == 'random' || command == 'rand' || command == 'r' return random(major) if command == 'random' || command == 'rand' || command == 'r'


# if we're operating on a List # if we're operating on a List
if storage.list_exists?(command) list = command
return delete_list(command) if major == 'delete' if storage.list_exists?(list)
return detail_list(command) unless major return delete_list(list) if major == 'delete'
return detail_list(list) unless major
unless minor == 'delete' unless minor == 'delete'
return add_item(command,major,minor) if minor return add_item(list,major,minor) if minor
return add_item(command,major,stdin.read) if stdin.stat.size > 0 return add_item(list,major,stdin.read) if stdin.stat.size > 0
return search_list_for_item(command, major) return search_list_for_item(list, major)
end end
end end


Expand Down Expand Up @@ -157,18 +158,18 @@ def detail_list(name)
# Public: opens the Item. # Public: opens the Item.
# #
# Returns nothing. # Returns nothing.
def open(major, minor) def open(key, value)
if storage.list_exists?(major) if storage.list_exists?(key)
list = List.find(major) list = List.find(key)
if minor if value
item = storage.items.detect { |item| item.name == minor } item = storage.items.detect { |item| item.name == value }
output "#{cyan("Boom!")} We just opened #{yellow(Platform.open(item))} for you." output "#{cyan("Boom!")} We just opened #{yellow(Platform.open(item))} for you."
else else
list.items.each { |item| Platform.open(item) } list.items.each { |item| Platform.open(item) }
output "#{cyan("Boom!")} We just opened all of #{yellow(major)} for you." output "#{cyan("Boom!")} We just opened all of #{yellow(key)} for you."
end end
else else
item = storage.items.detect { |item| item.name == major } item = storage.items.detect { |item| item.name == key }
output "#{cyan("Boom!")} We just opened #{yellow(Platform.open(item))} for you." output "#{cyan("Boom!")} We just opened #{yellow(Platform.open(item))} for you."
end end
end end
Expand Down
10 changes: 3 additions & 7 deletions lib/kaboom/platform/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ def open_file file


def edit json_file def edit json_file
if $EDITOR if $EDITOR
if block_given? return yield if block_given?
yield
else system "`echo $EDITOR` #{json_file} &"
system "`echo $EDITOR` #{json_file} &"
end
else else
open_file json_file open_file json_file
end end

"Make your edits, and do be sure to save."
end end


def copy item def copy item
Expand Down

0 comments on commit 648f0e4

Please sign in to comment.