lib/likeable/module_methods.rb in likeable-0.0.5 vs lib/likeable/module_methods.rb in likeable-0.1.0

- old
+ new

@@ -82,52 +82,28 @@ def find_one=(find_one) @find_one = find_one end def user_class - @user_class ||= ::User + begin + @user_class ||= ::User + rescue NameError + nil + end end - def user_class=(user) - raise "User must be a class #{user.inspect}" unless user.class == Class - @user_class = user + def user_class=(klass) + raise ArgumentError, "Argument must be a class" unless klass.is_a?(Class) + @user_class = klass end # Likeable.setup do |like| # like.redis = Redis.new(#...) # like.find_one = lambda {|klass, id | klass.where(:id => id)} # like.find_many = lambda {|klass, ids| klass.where(:id => ids)} - # like.classes = Spot, Comment # end - - - def include_in_class(klass, include_item) - case - when defined?(Rails::Application) - Rails::Application.class_eval do - config.to_prepare do - klass.send :include, include_item - end - end - else - klass.send :include, include_item - end - end - - def make_classes_likeable - classes.each do |klass| - include_in_class(klass, Likeable) - end - end - - def give_users_like_ability - include_in_class user_class, ::Likeable::UserMethods - end - def setup(&block) yield self unless block.blank? - make_classes_likeable - give_users_like_ability true end end -end \ No newline at end of file +end