lib/rating/models/rating/rate.rb in rating-0.10.0 vs lib/rating/models/rating/rate.rb in rating-0.11.0
- old
+ new
@@ -21,23 +21,19 @@
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)
- return record if record.persisted? && value == record.value
-
metadata.each { |k, v| record[k] = v } if metadata.present?
record.value = value
record.save
record
end
def self.rate_for(author:, extra_scopes: {}, resource:, scopeable: nil)
- attributes = { author: author, resource: resource, scopeable: scopeable }.merge(extra_scopes)
-
- find_by attributes
+ find_by extra_scopes.merge(author: author, resource: resource, scopeable: scopeable)
end
private
def update_rating