Skip to content

Commit

Permalink
add items cmd to dump tags per item
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Apr 8, 2012
1 parent 97bf88f commit c0b6565
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/tag/runner.rb
Expand Up @@ -50,5 +50,10 @@ def tree(options={})
def models
puts Tag::Store.models
end

desc 'list all items with their tags'
def items
puts Tag.store.items
end
end
end
10 changes: 10 additions & 0 deletions lib/tag/store.rb
Expand Up @@ -64,5 +64,15 @@ def delete_tags(*tags)
tags.each {|tag| @hash.delete(tag) }
save
end

def items
@hash.each_with_object({}) do |(tag,items),acc|
items.each do |item|
(acc[item] ||= []) << tag
end
end.sort_by {|e| e[0] }.map do |k,v|
"#{k}\t#{v.uniq.join(', ')}"
end
end
end
end
1 change: 1 addition & 0 deletions spec/helper.rb
@@ -1,5 +1,6 @@
gem 'minitest' unless ENV['NO_RUBYGEMS']
require 'minitest/spec'
require 'minitest/autorun' unless $0.end_with?('/m')
require 'tag'
require 'fileutils'
require 'bahia'
Expand Down
7 changes: 7 additions & 0 deletions spec/runner_spec.rb
Expand Up @@ -119,4 +119,11 @@ def tagged(tag)
tag 'models'
stdout.split("\n").must_equal ['default', 'physicist']
end

it "items prints items with tags" do
tag 'add feynman -t funny'
tag 'add einstein -t bighead,postal'
tag 'items'
stdout.split("\n").must_equal ["einstein\tbighead, postal", "feynman\tfunny"]
end
end

0 comments on commit c0b6565

Please sign in to comment.