195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/opinions.rb', line 195
def initialize(*args)
super
self.class.registered_opinions.each do |opinion|
self.class.send :define_method, :"#{opinion}_by" do |*args|
opinionated, time = *args
time = time || Time.now.utc
e = Opinion.new(object: opinionated, target: self, opinion: opinion)
true & e.persist(time: time)
end
self.class.send :define_method, :"cancel_#{opinion}_by" do |opinionated|
true & Opinion.new(object: opinionated, target: self, opinion: opinion).remove
end
self.class.send :define_method, :"#{opinion}_votes" do
lookup_key_builder = KeyBuilder.new(object: self, opinion: opinion)
keys = Opinions.backend.keys_matching(lookup_key_builder.key + "*")
keys.collect do |key_name|
OpinionFactory.new(from_target: key_name).opinion
end.flatten
end
end
end
|