class Rating::Rate
Public Class Methods
create(author:, extra_scopes:, metadata:, resource:, scopeable: nil, value:)
click to toggle source
# File lib/rating/models/rating/rate.rb, line 22 def self.create(author:, extra_scopes:, metadata:, resource:, scopeable: nil, value:) attributes = { author: author, resource: resource, scopeable: scopeable }.merge(extra_scopes) record = find_or_initialize_by(attributes) metadata.each { |k, v| record[k] = v } if metadata.present? record.value = value record.save record end
rate_for(author:, extra_scopes: {}, resource:, scopeable: nil)
click to toggle source
# File lib/rating/models/rating/rate.rb, line 34 def self.rate_for(author:, extra_scopes: {}, resource:, scopeable: nil) find_by extra_scopes.merge(author: author, resource: resource, scopeable: scopeable) end
Private Instance Methods
update_rating()
click to toggle source
# File lib/rating/models/rating/rate.rb, line 40 def update_rating ::Rating::Rating.update_rating resource, scopeable end