Created
November 20, 2012 02:09
-
-
Save anonymous/4115499 to your computer and use it in GitHub Desktop.
super hack
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
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 |
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
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