83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/seems_rateable/model.rb', line 83
def seems_rateable(opts={})
has_many :rates_without_dimension, -> { where(dimension: nil) }, :as => :rateable, :class_name => SeemsRateable::Rate, :dependent => :destroy
has_many :raters_without_dimension, :through => :rates_without_dimension, :source => :rater
has_one :rate_average_without_dimension, -> { where(dimension: nil) }, :as => :cacheable, :class_name => SeemsRateable::CachedRating, :dependent => :destroy
@permission = opts[:allow_update] ? true : false
def self.can_update?
@permission
end
def self.rateable?
true
end
if opts[:dimensions].is_a?(Array)
opts[:dimensions].each do |dimension|
has_many :"#{dimension}_rates", -> { where(dimension: dimension.to_s) }, :dependent => :destroy, :class_name => SeemsRateable::Rate, :as => :rateable
has_many :"#{dimension}_raters", :through => :"#{dimension}_rates", :source => :rater
has_one :"#{dimension}_average", -> { where(dimension: dimension.to_s) }, :as => :cacheable, :class_name => SeemsRateable::CachedRating, :dependent => :destroy
end
end
end
|