module Missingly::Matchers::ClassMethods
Public Instance Methods
_define_method(*args, &block)
click to toggle source
# File lib/missingly/matchers.rb, line 91 def _define_method(*args, &block) define_method(*args, &block) end
handle_missingly(matcher, options={}, &block)
click to toggle source
# File lib/missingly/matchers.rb, line 14 def handle_missingly(matcher, options={}, &block) undef_parent_missingly_methods matcher undef_normal_missingly_methods matcher if options[:with] setup_custom_handler(matcher, options, &block) elsif block_given? setup_block_handlers(matcher, options, &block) elsif options[:to] setup_delegation_handlers(matcher, options, options[:to]) end end
inherited(subclass)
click to toggle source
# File lib/missingly/matchers.rb, line 95 def inherited(subclass) matchers = self.missingly_matchers subclass.class_eval do @missingly_matchers = matchers.clone end missingly_subclasses << subclass end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/missingly/matchers.rb, line 103 def method_missing(method_name, *args, &block) missingly_matchers.values.each do |matcher| next unless matcher.should_respond_to?(self, method_name) next unless matcher.options[:class_method] Missingly::Mutex.synchronize do missingly_methods_for_matcher(matcher.matchable) << method_name returned_value = matcher.define(self, method_name) missingly_subclasses.each do |subclass| subclass.undef_parent_missingly_methods matcher.matchable end return public_send(method_name, *args, &block) end end super end
missingly_matchers()
click to toggle source
# File lib/missingly/matchers.rb, line 79 def missingly_matchers @missingly_matchers ||= {} end
missingly_methods()
click to toggle source
# File lib/missingly/matchers.rb, line 83 def missingly_methods @missingly_methods ||= Hash.new() end
missingly_methods_for_matcher(matcher)
click to toggle source
# File lib/missingly/matchers.rb, line 87 def missingly_methods_for_matcher(matcher) missingly_methods[matcher] ||= [] end
missingly_subclasses()
click to toggle source
# File lib/missingly/matchers.rb, line 75 def missingly_subclasses @missingly_subclasses ||= [] end
respond_to_missing?(method_name, include_all)
click to toggle source
Calls superclass method
# File lib/missingly/matchers.rb, line 123 def respond_to_missing?(method_name, include_all) self.missingly_matchers.values.each do |matcher| return true if matcher.should_respond_to?(self, method_name.to_sym) && matcher.options[:class_method] end super end
setup_block_handlers(matcher, options, &block)
click to toggle source
# File lib/missingly/matchers.rb, line 31 def setup_block_handlers(matcher, options, &block) case matcher when Array then missingly_matchers[matcher] = ArrayBlockMatcher.new(matcher, options, block) when Regexp then missingly_matchers[matcher] = RegexBlockMatcher.new(matcher, options, block) end end
setup_custom_handler(matcher, options, &block)
click to toggle source
# File lib/missingly/matchers.rb, line 27 def setup_custom_handler(matcher, options, &block) missingly_matchers[matcher] = options[:with].new(matcher, options, block) end
setup_delegation_handlers(matcher, options, to)
click to toggle source
# File lib/missingly/matchers.rb, line 38 def setup_delegation_handlers(matcher, options, to) case matcher when Array then missingly_matchers[matcher] = ArrayDelegateMatcher.new(matcher, options, to) when Regexp then missingly_matchers[matcher] = RegexDelegateMatcher.new(matcher, options, to) end end
undef_missingly_methods(methods)
click to toggle source
# File lib/missingly/matchers.rb, line 61 def undef_missingly_methods(methods) methods.each do |method| begin undef_method method rescue NameError eval <<-RUBY class << self undef_method #{method.inspect} end RUBY end end end
undef_normal_missingly_methods(matcher)
click to toggle source
# File lib/missingly/matchers.rb, line 57 def undef_normal_missingly_methods(matcher) undef_missingly_methods(missingly_methods_for_matcher(matcher)) end
undef_parent_missingly_methods(matcher)
click to toggle source
# File lib/missingly/matchers.rb, line 45 def undef_parent_missingly_methods(matcher) superclass = self.superclass matchers = [] while superclass.respond_to?(:missingly_methods_for_matcher) matchers.concat superclass.missingly_methods_for_matcher(matcher) superclass = superclass.superclass end undef_missingly_methods(matchers) end