Skip to content

Commit

Permalink
a more agnostic way to fetch tags per url
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed May 9, 2012
1 parent 008d50b commit b5ad931
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/urls/runner.rb
Expand Up @@ -77,11 +77,7 @@ def list(query=nil, options={})
choices = menu urls.map(&:name)
Urls.copy choices
else
urls = urls.map {|e| e.attributes }
if !(url_tags = Urls.tagged_items).empty?
urls.each {|e| e[:tags] = url_tags[e[:name]] || '' }
options[:fields] << :tags
end
options[:fields] << :tags unless Url.url_tags.empty?
puts table(urls, options)
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/urls/url.rb
Expand Up @@ -22,6 +22,18 @@ def self.urlify(url)
url.include?('://') ? url : "http://#{url}"
end

def self.url_tags
@url_tags ||= Urls.tagged_items
end

def tags
tag_list.join(", ")
end

def tag_list
@tag_list ||= self.class.url_tags[name].to_s.split(/\s*,\s*/)
end

before :save do
self.name = self.class.urlify(name)
end
Expand Down

0 comments on commit b5ad931

Please sign in to comment.