Module: MethodDecorator
- Extended by:
- ActiveSupport::Concern
- 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 =
'3.0.2'
Class Method Summary
collapse
Class Method Details
.call_original_method(target_context, target_method_name, *original_args, &original_block) ⇒ Object
64
65
66
67
68
|
# File 'lib/method_decorator.rb', line 64
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
20
21
22
23
24
25
|
# File 'lib/method_decorator.rb', line 20
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
70
71
72
73
74
75
76
|
# File 'lib/method_decorator.rb', line 70
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
78
79
80
|
# File 'lib/method_decorator.rb', line 78
def target_type_from_context(target_context)
target_context.class.eql?(Class) ? :singleton : :class
end
|