Module: EagerBeaver

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

Defined Under Namespace

Modules: ClassMethods Classes: MethodHandler

Constant Summary collapse

VERSION =
"0.0.4"

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_handlers.each do |method_handler|
    mh = configure_handler method_handler
    if mh.handles?(method_name)
      method_string = mh.evaluate mh.handle
      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_handler(handler) ⇒ Object



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

def configure_handler(handler)
  mh = handler.dup
  mh.original_receiver = self
  mh.original_receiver.class.context = mh
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_handlers.each do |method_handler|
    mh = configure_handler method_handler
    return true if mh.handles?(method_name)
  end
  super
end