Class: Likeable::Like
- Inherits:
-
Object
- Object
- Likeable::Like
- Defined in:
- lib/likeable/like.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#like_user ⇒ Object
Returns the value of attribute like_user.
-
#target ⇒ Object
Returns the value of attribute target.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(options = {}) ⇒ Like
constructor
A new instance of Like.
- #to_hash(type = :full) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Like
Returns a new instance of Like.
6 7 8 9 10 11 |
# File 'lib/likeable/like.rb', line 6 def initialize( = {}) self.created_at = Time.at([:time].try(:to_f)||Time.now) self.target = [:target] self.user_id = [:user].try(:id) || [:user_id] self.like_user = [:user] end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/likeable/like.rb', line 4 def created_at @created_at end |
#like_user ⇒ Object
Returns the value of attribute like_user.
4 5 6 |
# File 'lib/likeable/like.rb', line 4 def like_user @like_user end |
#target ⇒ Object
Returns the value of attribute target.
4 5 6 |
# File 'lib/likeable/like.rb', line 4 def target @target end |
#user_id ⇒ Object
Returns the value of attribute user_id.
4 5 6 |
# File 'lib/likeable/like.rb', line 4 def user_id @user_id end |
Instance Method Details
#id ⇒ Object
13 14 15 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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 ⇒ Object
17 18 19 20 21 |
# File 'lib/likeable/like.rb', line 17 def user @user ||= like_user @user ||= Likeable.find_one(Likeable.user_class, user_id) @user end |