Module: MonkeyBars
- Includes:
- Patch, Validation
- Defined in:
- lib/monkey_bars.rb,
lib/monkey_bars/patch.rb,
lib/monkey_bars/errors.rb,
lib/monkey_bars/version.rb,
lib/monkey_bars/validation.rb
Defined Under Namespace
Modules: Patch, SuperSuper, Validation
Classes: MismatchedClassMethodArityError, MismatchedInstanceMethodArityError, NewClassMethodAlreadyExistsError, NewConstantAlreadyExistsError, NewInstanceMethodAlreadyExistsError, NoPatchableClassMethodFoundError, NoPatchableInstanceMethodFoundError, NoPatchableMonkeyFoundError, NoPatchableVersionCheckError, NoPatchableVersionFoundError, PatchAlreadyPerformedError, PatchConstantNotFoundError, PatchableClassMethodIsNotPrivateError, PatchableClassMethodIsNotProtectedError, PatchableClassMethodIsPrivateError, PatchableClassMethodIsProtectedError, PatchableInstanceMethodIsNotPrivateError, PatchableInstanceMethodIsNotProtectedError, PatchableInstanceMethodIsPrivateError, PatchableInstanceMethodIsProtectedError, PrepareForPatchingAlreadyPerformedError
Constant Summary
collapse
- VERSION =
"0.2.1"
Class Method Summary
collapse
Instance Method Summary
collapse
-
#new_class_methods(&block) ⇒ Object
-
#new_constants(&block) ⇒ Object
-
#new_instance_methods(&block) ⇒ Object
-
#patch(monkey, version:, version_check:, &block) ⇒ Object
(also: #🐵)
-
#patch! ⇒ Object
-
#patch_class_methods(ignore_arity_errors: false, include_super_super: false, &block) ⇒ Object
-
#patch_constants(&block) ⇒ Object
-
#patch_instance_methods(ignore_arity_errors: false, include_super_super: false, &block) ⇒ Object
-
#post_patch(&block) ⇒ Object
-
#prepare_for_patching(monkey, version:, version_check:, patch_immediately: false, &block) ⇒ Object
Class Method Details
.extended(monkey_patcher) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/monkey_bars.rb', line 12
def self.extended(monkey_patcher)
monkey_patcher.instance_variable_set(:@monkey_patcher_name, monkey_patcher.name)
monkey_patcher.instance_variable_set(:@patch_class_methods, [])
monkey_patcher.instance_variable_set(:@new_class_methods, [])
monkey_patcher.instance_variable_set(:@patch_instance_methods, [])
monkey_patcher.instance_variable_set(:@new_instance_methods, [])
monkey_patcher.instance_variable_set(:@patch_constants, [])
monkey_patcher.instance_variable_set(:@new_constants, [])
end
|
Instance Method Details
#new_class_methods(&block) ⇒ Object
85
86
87
|
# File 'lib/monkey_bars.rb', line 85
def new_class_methods(&block)
@new_class_methods << block
end
|
#new_constants(&block) ⇒ Object
105
106
107
|
# File 'lib/monkey_bars.rb', line 105
def new_constants(&block)
@new_constants << block
end
|
#new_instance_methods(&block) ⇒ Object
97
98
99
|
# File 'lib/monkey_bars.rb', line 97
def new_instance_methods(&block)
@new_instance_methods << block
end
|
#patch(monkey, version:, version_check:, &block) ⇒ Object
Also known as:
🐵
22
23
24
25
26
27
28
29
30
|
# File 'lib/monkey_bars.rb', line 22
def patch(monkey, version:, version_check:, &block)
prepare_for_patching(
monkey,
version: version,
version_check: version_check,
patch_immediately: true,
&block
)
end
|
#patch! ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/monkey_bars.rb', line 49
def patch!
if @patch_performed
raise(PatchAlreadyPerformedError.new(@monkey_patcher_name))
end
if @patch_class_methods.empty? &&
@new_class_methods.empty? &&
@patch_instance_methods.empty? &&
@new_instance_methods.empty? &&
@patch_constants.empty? &&
@new_constants.empty?
warn "[#{self}] No methods or constants defined. Maybe you're not calling `#patch!` last?"
end
ensure_monkey_exists
ensure_patchable_version
ensure_patch_instance_methods_are_valid
ensure_new_instance_methods_are_valid
ensure_patch_class_methods_are_valid
ensure_new_class_methods_are_valid
ensure_patch_constants_are_valid
ensure_new_constants_are_valid
perform_patch
@patch_performed = true
end
|
#patch_class_methods(ignore_arity_errors: false, include_super_super: false, &block) ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/monkey_bars.rb', line 77
def patch_class_methods(ignore_arity_errors: false, include_super_super: false, &block)
@patch_class_methods << {
block: block,
ignore_arity_errors: ignore_arity_errors,
include_super_super: include_super_super
}
end
|
#patch_constants(&block) ⇒ Object
101
102
103
|
# File 'lib/monkey_bars.rb', line 101
def patch_constants(&block)
@patch_constants << block
end
|
#patch_instance_methods(ignore_arity_errors: false, include_super_super: false, &block) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/monkey_bars.rb', line 89
def patch_instance_methods(ignore_arity_errors: false, include_super_super: false, &block)
@patch_instance_methods << {
block: block,
ignore_arity_errors: ignore_arity_errors,
include_super_super: include_super_super
}
end
|
#post_patch(&block) ⇒ Object
109
110
111
|
# File 'lib/monkey_bars.rb', line 109
def post_patch(&block)
@post_patch_block = block
end
|
#prepare_for_patching(monkey, version:, version_check:, patch_immediately: false, &block) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/monkey_bars.rb', line 33
def prepare_for_patching(monkey, version:, version_check:, patch_immediately: false, &block)
if @prepare_for_patching_performed
raise(PrepareForPatchingAlreadyPerformedError.new(@monkey_patcher_name))
end
@monkey = monkey
@version = version
@version_check_block = version_check
yield if block_given?
patch! if patch_immediately
@prepare_for_patching_performed = true
end
|