Class: Contracts::MethodHandler
- Inherits:
-
Object
- Object
- Contracts::MethodHandler
- Defined in:
- lib/contracts/method_handler.rb
Overview
Handles class and instance methods addition Represents single such method
Constant Summary collapse
- METHOD_REFERENCE_FACTORY =
{ :class_methods => SingletonMethodReference, :instance_methods => MethodReference, }
- RAW_METHOD_STRATEGY =
{ :class_methods => lambda { |target, name| target.method(name) }, :instance_methods => lambda { |target, name| target.instance_method(name) }, }
Instance Method Summary collapse
-
#handle ⇒ Object
Handles method addition.
-
#initialize(method_name, is_class_method, target) ⇒ MethodHandler
constructor
Creates new instance of MethodHandler.
Constructor Details
#initialize(method_name, is_class_method, target) ⇒ MethodHandler
Creates new instance of MethodHandler
22 23 24 25 26 |
# File 'lib/contracts/method_handler.rb', line 22 def initialize(method_name, is_class_method, target) @method_name = method_name @is_class_method = is_class_method @target = target end |
Instance Method Details
#handle ⇒ Object
Handles method addition
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/contracts/method_handler.rb', line 29 def handle return unless engine? return if decorators.empty? validate_decorators! validate_pattern_matching! engine.add_method_decorator(method_type, method_name, decorator) mark_pattern_matching_decorators method_reference.make_alias(target) redefine_method end |