Module: TouchTouch::Toucher::ClassMethods

Defined in:
lib/touch_touch/toucher.rb

Instance Method Summary collapse

Instance Method Details

#touch_alias(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/touch_touch/toucher.rb', line 13

def touch_alias(*args)
  al = args.first.to_s
  pa = args.second
  classs = pa[:class]
  limit = pa[:limit]
  class_name = classs.name.downcase

  define_method(al.to_sym) do |arg|
    raise(ClassNotDefined, "Class is not defined") unless arg.instance_of? classs

    redis = TouchTouch::Redis.new
    redis.set(self.class, self.id, al, arg.class, arg.id, limit)
  end

  define_method("#{al}_#{class_name.pluralize}".to_sym) do
    redis = TouchTouch::Redis.new
    touchee_ids = redis.get(self.class, self.id, al, classs)
    classs.find(touchee_ids)
  end
end