Skip to content

Instantly share code, notes, and snippets.

@xander-miller
Last active November 24, 2015 19:23
Show Gist options
  • Save xander-miller/dbc20d895efe9316ec3d to your computer and use it in GitHub Desktop.
Save xander-miller/dbc20d895efe9316ec3d to your computer and use it in GitHub Desktop.
Happy to use an &&= operator
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