Module: MethodCop
- Defined in:
- lib/method_cop.rb,
lib/method_cop/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"- @@guards =
TODO: DRY this up
{}
- @@class_guards =
{}
Instance Method Summary collapse
- #guard_class_method(name, options) ⇒ Object
- #guard_class_method_internal(name, options) ⇒ Object
- #guard_method(name, options) ⇒ Object
- #guard_method_internal(name, options) ⇒ Object
- #method_added(name) ⇒ Object
- #singleton_method_added(name) ⇒ Object
Instance Method Details
#guard_class_method(name, options) ⇒ Object
38 39 40 |
# File 'lib/method_cop.rb', line 38 def guard_class_method(name, ) @@class_guards[name] = end |
#guard_class_method_internal(name, options) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/method_cop.rb', line 50 def guard_class_method_internal(name, ) @@method_to_guard_name = name @@method_to_guard_options = # there HAS to be a better way. need to look into it. class << self name = @@method_to_guard_name = @@method_to_guard_options @@method_to_guard_name = nil @@method_to_guard_options = nil method = name.to_sym original_method = "#{name}_orig".to_sym alias_method original_method, method define_method(method) do |*args| unless [:with].nil? unless !self.send([:with].to_sym) self.send(original_method, *args) else # THIS METHOD IS UNDER ARREST nil end else # no method to guard with was given self.send(original_method, *args) end end end end |
#guard_method(name, options) ⇒ Object
6 7 8 |
# File 'lib/method_cop.rb', line 6 def guard_method(name, ) @@guards[name] = end |
#guard_method_internal(name, options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/method_cop.rb', line 18 def guard_method_internal(name, ) method = name.to_sym original_method = "#{name}_orig".to_sym alias_method original_method, method define_method(method) do |*args| unless [:with].nil? unless !self.send([:with].to_sym) self.send(original_method, *args) else # THIS METHOD IS UNDER ARREST nil end else # no method to guard with was given self.send(original_method, *args) end end end |
#method_added(name) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/method_cop.rb', line 10 def method_added(name) unless @@guards[name].nil? = @@guards[name] @@guards = @@guards.delete(name) guard_method_internal(name, ) end end |
#singleton_method_added(name) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/method_cop.rb', line 42 def singleton_method_added(name) unless @@class_guards[name].nil? = @@class_guards[name] @@class_guards = @@class_guards.delete(name) guard_class_method_internal(name, ) end end |