Class: Rating::Rate

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/rating/models/rating/rate.rb

Class Method Summary collapse

Class Method Details

.create(author:, extra_scopes:, metadata:, resource:, value:, scopeable: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rating/models/rating/rate.rb', line 27

def self.create(author:, extra_scopes:, metadata:, resource:, value:, scopeable: nil)
  attributes = { author:, resource:, scopeable: }.merge(extra_scopes)
  record = find_or_initialize_by(attributes)

  .each { |k, v| record[k] = v } if .present?

  record.value = value
  record.save

  record
end

.rate_for(author:, resource:, extra_scopes: {}, scopeable: nil) ⇒ Object



39
40
41
# File 'lib/rating/models/rating/rate.rb', line 39

def self.rate_for(author:, resource:, extra_scopes: {}, scopeable: nil)
  find_by extra_scopes.merge(author:, resource:, scopeable:)
end