Skip to content

Instantly share code, notes, and snippets.

@BinaryMuse
Forked from anonymous/output
Created November 20, 2012 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BinaryMuse/4119989 to your computer and use it in GitHub Desktop.
Save BinaryMuse/4119989 to your computer and use it in GitHub Desktop.
super hack
module Homepage
module V2
class Board
include Redis::Objects
value :name
value :exists
counter :views
set :comment_ids
set :like_user_ids
attr_reader :id
def initialize(id)
@id = id
end
def self.find(id)
if redis.exists("board:#{id}:exists")
new(id)
else
populate(::Board.find(id))
end
end
def self.populate(ar_board)
board = new(ar_board.id)
board.name = ar_board.name
Array(ar_board.likes).map {|l| board. like_user_ids << l.user_id }
board.views.incr(ar_board.views)
board.exists = true
board
end
def self.redis
Redis.new(db:10)
end
end
end
end
board = Homepage::V2::Board.find(2)
=> #<Homepage::V2::Board:0x007ff4466b9968 @id=2>
pry(main)> board.views.to_i
=> 518
pry(main)> board.name
=> #<Redis::Value "SXSW Band Picks 2012">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment