monkey_bars 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b35082ce948e0728f731d785776d4ac9bf43cffe2cde650caf8c4433ef7cf7ff
4
- data.tar.gz: bac9b0bf1d3da1ceb52a167ad0289192d66e9a815bf05dda126a7d62f771aa4a
3
+ metadata.gz: 959654729be5d09d997d89340df3d00652a0a39f962cbf0f87a3223a24b22195
4
+ data.tar.gz: b36eaea242ef45cb939040f6436af3ed3f9cb806f261141ab5c68e9ba7c24967
5
5
  SHA512:
6
- metadata.gz: f4e70ba31cae555f6ad5766602f9d21fdbf04b79614d338b28ea6f75c6f6ce65f1760d45d0de6c6f35d8e49a66144757cbbc396b5a18dc0b4ccd7bdc31ab7ea8
7
- data.tar.gz: c6cff1ac6df1ba73080973a262a7812ff104ec1e93b5bcfbebbce7d1a1727ce20558d11000dc402bf42765f3fbd7fa829f8ce9a34d671c83fe9dd38470ffcd45
6
+ metadata.gz: 5084d4cc7c224bf0fcf5eeaae3aa02da22ea2b5cac93e8561983bb1d1d3d61a371f7a5401d319117b9efce894ff2e85c1f908a7e2a8777d585791160a4959359
7
+ data.tar.gz: 4633ed06204dd319134fd7c05ff437c649c1c441ab890abe4b3c51b38bcc02c0bc976c41f7e634d17b9bc461b2d0294007bc055f82fa8c71b47e4770322eacd2
data/README.md CHANGED
@@ -73,6 +73,7 @@ declared inside a block and then applied with `patch` (immediately) or
73
73
  - `patch!` applies a prepared patch
74
74
 
75
75
  If `patch!` runs without any methods or constants defined, it emits a warning.
76
+ Calling `prepare_for_patching` or `patch!` more than once raises an error.
76
77
 
77
78
  The `monkey` can be:
78
79
 
@@ -242,6 +243,7 @@ MonkeyBars raises specific errors to keep patches safe and explicit:
242
243
  - `MonkeyBars::PatchConstantNotFoundError`
243
244
  - `MonkeyBars::NewConstantAlreadyExistsError`
244
245
  - `MonkeyBars::PatchAlreadyPerformedError`
246
+ - `MonkeyBars::PrepareForPatchingAlreadyPerformedError`
245
247
 
246
248
  ## Development
247
249
 
data/docs/llm-usage.md CHANGED
@@ -46,6 +46,8 @@ compares it with `version` using exact equality. Mismatches raise
46
46
  - `prepare_for_patching(...)` validates and stores the patch.
47
47
  - `patch!` applies a previously prepared patch and can only be called once.
48
48
 
49
+ Calling `prepare_for_patching` more than once raises
50
+ `MonkeyBars::PrepareForPatchingAlreadyPerformedError`.
49
51
  Calling `patch!` more than once raises `MonkeyBars::PatchAlreadyPerformedError`.
50
52
 
51
53
  ## API reference
@@ -273,6 +275,9 @@ Use this section when the patch fails. The message usually suggests the fix.
273
275
  Move it to `patch_constants`.
274
276
  - `MonkeyBars::PatchAlreadyPerformedError`: `patch!` was called twice.
275
277
  Ensure you only call `patch!` once per prepared patch.
278
+ - `MonkeyBars::PrepareForPatchingAlreadyPerformedError`:
279
+ `prepare_for_patching` was called twice. Ensure you only prepare once per
280
+ patcher.
276
281
 
277
282
  ## Best practices for LLMs
278
283
 
@@ -120,4 +120,10 @@ module MonkeyBars
120
120
  super("[#{patcher_name}] Couldn't find constant `#{constant}` on `#{monkey}` despite it being marked as patchable. Perhaps move it to the `new_constants` block?")
121
121
  end
122
122
  end
123
+
124
+ class PrepareForPatchingAlreadyPerformedError < StandardError
125
+ def initialize(patcher_name)
126
+ super("[#{patcher_name}] `#prepare_for_patching` has already been called and cannot be called again")
127
+ end
128
+ end
123
129
  end
@@ -34,7 +34,7 @@ module MonkeyBars
34
34
  preexisting_instance_method => {block:, ignore_arity_errors:, include_super_super:}
35
35
  module_to_prepend.module_eval(&block)
36
36
  module_to_prepend.instance_methods.each do |method_name|
37
- next if module_to_prepend.protected_instance_methods.include?(method_name)
37
+ next if module_to_prepend.protected_method_defined?(method_name)
38
38
 
39
39
  if @monkey.protected_method_defined?(method_name)
40
40
  raise(PatchableInstanceMethodIsProtectedError.new(@monkey_patcher_name, monkey: @monkey, method: method_name))
@@ -126,7 +126,7 @@ module MonkeyBars
126
126
  preexisting_class_method => {block:, ignore_arity_errors:, include_super_super:}
127
127
  module_to_prepend.module_eval(&block)
128
128
  module_to_prepend.instance_methods.each do |method_name|
129
- next if module_to_prepend.protected_instance_methods.include?(method_name)
129
+ next if module_to_prepend.protected_method_defined?(method_name)
130
130
 
131
131
  if @monkey.singleton_class.protected_method_defined?(method_name)
132
132
  raise(PatchableClassMethodIsProtectedError.new(@monkey_patcher_name, monkey: @monkey, method: method_name))
@@ -216,7 +216,7 @@ module MonkeyBars
216
216
  module_to_redefine = Module.new
217
217
  module_to_redefine.module_eval(&redefined_constant)
218
218
  module_to_redefine.constants(false).each do |const_name|
219
- unless @monkey.constants(false).include?(const_name)
219
+ unless @monkey.const_defined?(const_name, false)
220
220
  raise(PatchConstantNotFoundError.new(@monkey_patcher_name, monkey: @monkey, constant: const_name))
221
221
  end
222
222
  end
@@ -233,7 +233,7 @@ module MonkeyBars
233
233
  module_to_include = Module.new
234
234
  module_to_include.module_eval(&new_constant)
235
235
  module_to_include.constants(false).each do |const_name|
236
- if @monkey.constants(false).include?(const_name)
236
+ if @monkey.const_defined?(const_name, false)
237
237
  raise(NewConstantAlreadyExistsError.new(@monkey_patcher_name, monkey: @monkey, constant: const_name))
238
238
  end
239
239
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MonkeyBars
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/monkey_bars.rb CHANGED
@@ -31,6 +31,10 @@ module MonkeyBars
31
31
  alias_method :🐵, :patch
32
32
 
33
33
  def prepare_for_patching(monkey, version:, version_check:, patch_immediately: false, &block)
34
+ if @prepare_for_patching_performed
35
+ raise(PrepareForPatchingAlreadyPerformedError.new(@monkey_patcher_name))
36
+ end
37
+
34
38
  @monkey = monkey
35
39
  @version = version
36
40
  @version_check_block = version_check
@@ -38,6 +42,8 @@ module MonkeyBars
38
42
  yield if block_given?
39
43
 
40
44
  patch! if patch_immediately
45
+
46
+ @prepare_for_patching_performed = true
41
47
  end
42
48
 
43
49
  def patch!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkey_bars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrés Rojas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-12 00:00:00.000000000 Z
11
+ date: 2026-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake