stable 1.20.0 → 1.20.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stable/version.rb +1 -1
  3. data/lib/stable.rb +30 -2
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62b2d2b99ffdecc5553ba21e97ceadf89bd02563c930e79d765875b941bb1bfa
4
- data.tar.gz: 89c84d540ca58cbec3935d3503d1f787677d1ebb506b6d909b00954ef88ad273
3
+ metadata.gz: 6e15bc20c1e3075bbcf961acf641350f5a86f28d344c4cdf10714d1f81e5cedb
4
+ data.tar.gz: 6c7e38b8cdb11d438057c612b7be9c7c0509ec627ff1702d5bb0a829cd4108f5
5
5
  SHA512:
6
- metadata.gz: 937aef6d33cb4e758035bf02abcbb660258051a69dfdb72565c39bdc17e47974bcf0e008d812a63e05c11e3328229e70a9e956e9c789eb9e2e67f72cfc57511c
7
- data.tar.gz: 1cff3aab0cdbe3c76f2e91e040f536ec4d5b73b61d3c6d39b956a5436f3d1d62a4290858fd8b8ae80da944914073135ba260cdcb3430bea2f28132d9f3c982fe
6
+ metadata.gz: 6f713c013b885c9297b227d46b8ee5195b4d38844f042a7c6df9706e605eaec397eceeac54cb40962df2f9cccef49ec617234f7abd42956026ecbd99e6d574bd
7
+ data.tar.gz: 59902723fb85cdde62aab42c994570d4f630f4373a046e90b6f955b2b6bbd296f091c63c06a0b0ce93671bfee8e1326addf6316858b48ac3a5ed850ba5fa1817
@@ -1,3 +1,3 @@
1
1
  module Stable
2
- VERSION = "1.20.0"
2
+ VERSION = "1.20.1"
3
3
  end
data/lib/stable.rb CHANGED
@@ -58,6 +58,34 @@ module Stable
58
58
  @storage = nil
59
59
  end
60
60
 
61
+ # This is the core method for observing a method on a class or module. It
62
+ # uses a dynamic module and `prepend` to intercept method calls without
63
+ # altering the original method.
64
+ #
65
+ # The design handles several complexities:
66
+ #
67
+ # 1. **Instance vs. Class Methods:** It accepts a `type` parameter to
68
+ # differentiate between instance and class methods. For class methods,
69
+ # it targets the singleton class (`klass.singleton_class`) to inject
70
+ # the wrapper.
71
+ #
72
+ # 2. **State Capture:** For instance methods, it captures the object's state
73
+ # (instance variables) *before* the method is called. This `prior` state
74
+ # is crucial for rehydrating the object during verification. State is not
75
+ # captured for class methods to prevent infinite loops, as the recording
76
+ # process itself may call class methods (e.g., `.name`).
77
+ #
78
+ # 3. **Method Binding:** It correctly handles both bound (`Method`) and
79
+ # unbound (`UnboundMethod`) method objects, ensuring `self` is correctly
80
+ # bound when the original method is eventually called.
81
+ #
82
+ # 4. **Fact Creation:** It gathers all relevant data—class name, method name,
83
+ # arguments, prior state, and the result or error—into a `Fact` object.
84
+ #
85
+ # 5. **Duplicate Prevention:** It generates a signature for each potential
86
+ # fact and checks if a fact with the same signature has already been
87
+ # recorded to prevent creating duplicate entries.
88
+ #
61
89
  def watch(klass, method_name, type: :instance)
62
90
  original_method = type == :instance ? klass.instance_method(method_name) : klass.method(method_name)
63
91
  target = type == :instance ? klass : klass.singleton_class
@@ -66,7 +94,7 @@ module Stable
66
94
  define_method(method_name) do |*args, **kwargs, &block|
67
95
  if Stable.enabled?
68
96
  begin
69
- prior = Stable.send(:_capture_state, self)
97
+ prior = type == :instance ? Stable.send(:_capture_state, self) : nil
70
98
  result = original_method.is_a?(UnboundMethod) ? original_method.bind(self).call(*args, **kwargs, &block) : original_method.call(*args, **kwargs, &block)
71
99
  fact = Fact.new(
72
100
  class_name: klass.name,
@@ -84,7 +112,7 @@ module Stable
84
112
  end
85
113
  result
86
114
  rescue => e
87
- prior = Stable.send(:_capture_state, self)
115
+ prior = type == :instance ? Stable.send(:_capture_state, self) : nil
88
116
  fact = Fact.new(
89
117
  class_name: klass.name,
90
118
  method_name: method_name,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.20.0
4
+ version: 1.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt