Last active
November 24, 2015 19:23
-
-
Save xander-miller/dbc20d895efe9316ec3d to your computer and use it in GitHub Desktop.
Happy to use an &&= operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserDecorator < Draper::Decorator | |
include Draper::LazyHelpers | |
delegate_all | |
class << self | |
def tagtionary | |
@tagionary ||= tagtionary!.clone | |
end | |
def tagtionary! | |
tag_ids = User.all.map {|u| u.tag_ids }.flatten.uniq | |
tags = Tag.find(tag_ids) | |
out = tags.map{|t| [t.id, t]}.to_h | |
@tagionary &&= out | |
out | |
end | |
end | |
def tags | |
object.tag_ids.map{|t_id| UserDecorator.tagtionary[t_id]} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment