Module: Ratable::Models::Ratee

Extended by:
ActiveSupport::Concern
Defined in:
lib/ratable/models/ratee.rb

Defined Under Namespace

Modules: ActiveRecordExtension, ActiveRecordInclusion

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#has_oneObject (readonly)

Returns the value of attribute has_one.



6
7
8
# File 'lib/ratable/models/ratee.rb', line 6

def has_one
  @has_one
end

Instance Method Details

#rate(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/ratable/models/ratee.rb', line 50

def rate(options={})
  options.reject! { |k| k == :ratee }
  if rating.present?
    create_rating(options)
  else
    ratings.create(options)
  end
end

#ratersObject



42
43
44
45
46
47
48
# File 'lib/ratable/models/ratee.rb', line 42

def raters
  if rating.present?
    rating.rater
  else
    ratings.includes(:rater).collect { |rating| rating.rater }
  end
end

#rating_averageObject



34
35
36
37
38
39
40
# File 'lib/ratable/models/ratee.rb', line 34

def rating_average
  if rating.present?
    ::Ratable::RatingAverage.new(ratings: rating, ratee: self)
  else
    ::Ratable::RatingAverage.new(ratings: ratings, ratee: self)
  end
end