Module: MethodDecorator
- Defined in:
- lib/method_decorator.rb,
lib/method_decorator/version.rb,
lib/method_decorator/decoration.rb,
lib/method_decorator/repository.rb
Defined Under Namespace
Classes: Decoration, Repository
Constant Summary
collapse
- VERSION =
'2.1.0'
Class Method Summary
collapse
Class Method Details
.call_original_method(target_context, target_method_name, *original_args, &original_block) ⇒ Object
35
36
37
38
39
|
# File 'lib/method_decorator.rb', line 35
def call_original_method(target_context, target_method_name, *original_args, &original_block)
target_class = target_class_from_context(target_context)
target_method = Repository.original_target_method_of(target_class, target_method_name)
target_method.bind(target_context).call(*original_args, &original_block)
end
|
.decorate(target_class, target_method_name, &decoration) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/method_decorator.rb', line 7
def decorate(target_class, target_method_name, &decoration)
raise 'target_method_name must be a symbol' unless target_method_name.is_a? Symbol
added = add_to_repository(decoration, target_class, target_method_name)
override_method(decoration, target_class, target_method_name) if added
added
end
|
.target_class_from_context(target_context) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/method_decorator.rb', line 41
def target_class_from_context(target_context)
if target_type_from_context(target_context).eql? :singleton
target_context.singleton_class
else
target_context.class
end
end
|
.target_type_from_context(target_context) ⇒ Object
49
50
51
|
# File 'lib/method_decorator.rb', line 49
def target_type_from_context(target_context)
target_context.class.eql?(Class) ? :singleton : :class
end
|