Class: Object

Inherits:
BasicObject
Defined in:
lib/do_not_want.rb

Class Method Summary collapse

Class Method Details

.do_not_want!(method_name, reason) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/do_not_want.rb', line 51

def self.do_not_want!(method_name, reason)
  original_method_name = ('do_not_want_original_' + method_name.to_s).to_sym
  self.send :alias_method, original_method_name, method_name

  self.send :define_method, method_name do |*args|
    original_method_name = ('do_not_want_original_' + method_name.to_s).to_sym
    use_real_method = DoNotWant.should_validate_for_caller(caller)
    if use_real_method
      return self.send original_method_name, *args
    end
    raise DoNotWant::NotSafe.new(self, method_name, reason)
  end
end