Module: EagerBeaver

Defined in:
lib/eager_beaver.rb,
lib/eager_beaver/version.rb,
lib/eager_beaver/method_matcher.rb

Defined Under Namespace

Modules: ClassMethods Classes: MethodMatcher

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/eager_beaver.rb', line 10

def method_missing(method_name, *args, &block)
  self.class.method_matchers.each do |method_matcher|
    mm = configure_matcher method_matcher
    if mm.match?(method_name)
      method_string = mm.evaluate mm.new_method_code_maker
      self.class.class_eval method_string, __FILE__, __LINE__ + 1
      return self.send(method_name, *args, &block)
    end
  end
  super
end

Class Method Details

.included(includer) ⇒ Object



6
7
8
# File 'lib/eager_beaver.rb', line 6

def self.included(includer)
  includer.extend(ClassMethods)
end

Instance Method Details

#configure_matcher(matcher) ⇒ Object



30
31
32
33
34
# File 'lib/eager_beaver.rb', line 30

def configure_matcher(matcher)
  mm = matcher.dup
  mm.original_receiver = self
  mm.original_receiver.class.context = mm
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/eager_beaver.rb', line 22

def respond_to_missing?(method_name, include_private=false)
  self.class.method_matchers.each do |method_matcher|
    mm = configure_matcher method_matcher
    return true if mm.match?(method_name)
  end
  super
end