Class: Like
- Inherits:
-
Object
- Object
- Like
- Defined in:
- app/models/like.rb
Overview
Convenience class for managing like activities
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
The object that is liked.
Class Method Summary collapse
- .build(subject, object) ⇒ Object
-
.find(subject, object) ⇒ Object
Find the children activity of activity_id liked by subject.
-
.find!(subject, object) ⇒ Object
Like #find but raises error if not found.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(activity) ⇒ Like
constructor
Initialize a new like activity.
- #save ⇒ Object
Constructor Details
#initialize(activity) ⇒ Like
Initialize a new like activity
26 27 28 |
# File 'app/models/like.rb', line 26 def initialize(activity) @like = activity end |
Instance Attribute Details
#object ⇒ Object (readonly)
The object that is liked. It can be an activity
35 36 37 |
# File 'app/models/like.rb', line 35 def object @object end |
Class Method Details
.build(subject, object) ⇒ Object
20 21 22 |
# File 'app/models/like.rb', line 20 def build(subject, object) new object.new_like(subject) end |
.find(subject, object) ⇒ Object
Find the children activity of activity_id liked by subject
7 8 9 10 11 12 |
# File 'app/models/like.rb', line 7 def find(subject, object) like = new(object.liked_by(subject).first) # Cache object to make it available before it is destroyed like.object like end |
.find!(subject, object) ⇒ Object
Like #find but raises error if not found
15 16 17 18 |
# File 'app/models/like.rb', line 15 def find!(subject, object) find(subject, object) || raise(ActiveRecord::RecordNotFound) end |
Instance Method Details
#destroy ⇒ Object
46 47 48 |
# File 'app/models/like.rb', line 46 def destroy @like.destroy end |
#save ⇒ Object
30 31 32 |
# File 'app/models/like.rb', line 30 def save @like.save end |