class Likeable::Like
Attributes
created_at[RW]
like_user[RW]
target[RW]
user_id[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/likeable/like.rb, line 6 def initialize(options = {}) self.created_at = Time.at(options[:time].try(:to_f)||Time.now) self.target = options[:target] self.user_id = options[:user].try(:id) || options[:user_id] self.like_user = options[:user] end
Public Instance Methods
id()
click to toggle source
# File lib/likeable/like.rb, line 13 def id Digest::SHA1.hexdigest("#{user_id}#{target.class}#{target.id}#{created_at}") end
to_hash(type=:full)
click to toggle source
# File lib/likeable/like.rb, line 23 def to_hash(type=:full) { :created_at => created_at.iso8601, :type => target.class.name.gsub(/^[A-Za-z]+::/, '').underscore.downcase.to_sym, :target => target.to_hash(type), :user => user.to_hash(type) } end
user()
click to toggle source
# File lib/likeable/like.rb, line 17 def user @user ||= like_user @user ||= Likeable.find_one(Likeable.user_class, user_id) @user end