Module: Rateable::IsRateable::InstanceMethods

Defined in:
lib/rateable/is_rateable.rb

Instance Method Summary collapse

Instance Method Details

#is_rateable?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rateable/is_rateable.rb', line 26

def is_rateable?
  true
end

#max_starsObject



30
31
32
# File 'lib/rateable/is_rateable.rb', line 30

def max_stars
  self.class.max_stars
end

#rate(user, stars) ⇒ Object

include instance methods that are needed



35
36
37
38
39
40
41
42
43
44
# File 'lib/rateable/is_rateable.rb', line 35

def rate(user,stars)
  raise "#{user.inspect} is not a rater" unless user.respond_to?(:is_rater?) and user.is_rater?
  rating = Rate.where(:rateable => self, :rater => user).first
  unless rating 
    rating = Rate.create(:rateable => self, :rater => user, :stars => stars) 
  else
    rating.stars = stars
  end
  rating.save
end