Class: Like

Inherits:
Object
  • Object
show all
Defined in:
app/models/like.rb

Overview

Convenience class for managing like activities

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#objectObject (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

#destroyObject



46
47
48
# File 'app/models/like.rb', line 46

def destroy
  @like.destroy
end

#saveObject



30
31
32
# File 'app/models/like.rb', line 30

def save
  @like.save
end