stable 1.16.4 → 1.18.0
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 +4 -4
- data/lib/example/class_methods.rb +12 -0
- data/lib/example/kw_calculator.rb +6 -0
- data/lib/stable/fact.rb +15 -5
- data/lib/stable/version.rb +1 -1
- data/lib/stable.rb +24 -6
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e273db464150e7c0ece83faa1510fb3b94ca32a48072f867c659dc436bf3859f
|
4
|
+
data.tar.gz: 4ebcf45014456a2cb01e835e578d2b09fc3edfd6631e986c62b9d20fe7c47a83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf83e82322298736666f5f6bcd1bf13b9ac6ef20d71f4be8faca14cdcef845f3af88ec39227c4457cf1ad9bab416d1fa37c6890ed3e958609a70c7437325e65d
|
7
|
+
data.tar.gz: a8cc263e9d936fb34dfc60bf7d90b5793c0800143a3e2bd418ed4ea9cc9a6124caa2c166a62a21a32af0b9ea8cf49401adf9cfd0241ce307f564ee2613b3732e
|
data/lib/stable/fact.rb
CHANGED
@@ -8,17 +8,19 @@ module Stable
|
|
8
8
|
# outputs. it's a self-contained, serializable representation of a method's
|
9
9
|
# behavior at a specific point in time.
|
10
10
|
class Fact
|
11
|
-
attr_reader :class_name, :method_name, :args, :result, :error, :actual_result, :actual_error, :status, :uuid, :signature, :name, :source_file
|
11
|
+
attr_reader :class_name, :method_name, :method_type, :args, :kwargs, :result, :error, :actual_result, :actual_error, :status, :uuid, :signature, :name, :source_file
|
12
12
|
|
13
|
-
def initialize(class_name:, method_name:, args:, result: nil, error: nil, uuid: SecureRandom.uuid, name: nil, source_file: nil)
|
13
|
+
def initialize(class_name:, method_name:, args:, method_type: :instance, kwargs: {}, result: nil, error: nil, uuid: SecureRandom.uuid, name: nil, source_file: nil)
|
14
14
|
@class_name = class_name
|
15
15
|
@method_name = method_name
|
16
|
+
@method_type = method_type
|
16
17
|
@args = args
|
18
|
+
@kwargs = (kwargs || {}).transform_keys(&:to_sym)
|
17
19
|
@result = result
|
18
20
|
@error = error
|
19
21
|
@status = :pending
|
20
22
|
@uuid = uuid
|
21
|
-
@signature = Digest::SHA256.hexdigest("#{class_name}##{method_name}:#{args.to_json}")
|
23
|
+
@signature = Digest::SHA256.hexdigest("#{class_name}##{method_name}:#{args.to_json}:#{kwargs.to_json}")
|
22
24
|
@name = name || uuid.split('-').last
|
23
25
|
@source_file = source_file
|
24
26
|
end
|
@@ -32,8 +34,12 @@ module Stable
|
|
32
34
|
def run!
|
33
35
|
begin
|
34
36
|
klass = Object.const_get(class_name)
|
35
|
-
|
36
|
-
|
37
|
+
if method_type == :instance
|
38
|
+
instance = klass.new
|
39
|
+
@actual_result = instance.public_send(method_name, *args, **kwargs)
|
40
|
+
else
|
41
|
+
@actual_result = klass.public_send(method_name, *args, **kwargs)
|
42
|
+
end
|
37
43
|
if error
|
38
44
|
@status = :failed
|
39
45
|
elsif actual_result == result
|
@@ -73,7 +79,9 @@ module Stable
|
|
73
79
|
{
|
74
80
|
class: class_name,
|
75
81
|
method: method_name,
|
82
|
+
method_type: method_type,
|
76
83
|
args: args,
|
84
|
+
kwargs: kwargs,
|
77
85
|
result: result,
|
78
86
|
error: error,
|
79
87
|
uuid: uuid,
|
@@ -87,7 +95,9 @@ module Stable
|
|
87
95
|
new(
|
88
96
|
class_name: data['class'],
|
89
97
|
method_name: data['method'],
|
98
|
+
method_type: (data['method_type'] || :instance).to_sym,
|
90
99
|
args: data['args'],
|
100
|
+
kwargs: data['kwargs'],
|
91
101
|
result: data['result'],
|
92
102
|
error: data['error'],
|
93
103
|
uuid: data['uuid'],
|
data/lib/stable/version.rb
CHANGED
data/lib/stable.rb
CHANGED
@@ -57,17 +57,21 @@ module Stable
|
|
57
57
|
@storage = nil
|
58
58
|
end
|
59
59
|
|
60
|
-
def watch(klass, method_name)
|
61
|
-
original_method = klass.instance_method(method_name)
|
60
|
+
def watch(klass, method_name, type: :instance)
|
61
|
+
original_method = type == :instance ? klass.instance_method(method_name) : klass.method(method_name)
|
62
|
+
target = type == :instance ? klass : klass.singleton_class
|
63
|
+
|
62
64
|
wrapper_module = Module.new do
|
63
|
-
define_method(method_name) do |*args, &block|
|
65
|
+
define_method(method_name) do |*args, **kwargs, &block|
|
64
66
|
if Stable.enabled?
|
65
67
|
begin
|
66
|
-
result = original_method.bind(self).call(*args, &block)
|
68
|
+
result = original_method.is_a?(UnboundMethod) ? original_method.bind(self).call(*args, **kwargs, &block) : original_method.call(*args, **kwargs, &block)
|
67
69
|
fact = Fact.new(
|
68
70
|
class_name: klass.name,
|
69
71
|
method_name: method_name,
|
72
|
+
method_type: type,
|
70
73
|
args: args,
|
74
|
+
kwargs: kwargs,
|
71
75
|
result: result
|
72
76
|
)
|
73
77
|
unless Stable.send(:_fact_exists?, fact.signature)
|
@@ -80,7 +84,9 @@ module Stable
|
|
80
84
|
fact = Fact.new(
|
81
85
|
class_name: klass.name,
|
82
86
|
method_name: method_name,
|
87
|
+
method_type: type,
|
83
88
|
args: args,
|
89
|
+
kwargs: kwargs,
|
84
90
|
error: {
|
85
91
|
class: e.class.name,
|
86
92
|
message: e.message,
|
@@ -95,11 +101,23 @@ module Stable
|
|
95
101
|
raise e
|
96
102
|
end
|
97
103
|
else
|
98
|
-
original_method.bind(self).call(*args, &block)
|
104
|
+
original_method.is_a?(UnboundMethod) ? original_method.bind(self).call(*args, **kwargs, &block) : original_method.call(*args, **kwargs, &block)
|
99
105
|
end
|
100
106
|
end
|
101
107
|
end
|
102
|
-
|
108
|
+
target.prepend(wrapper_module)
|
109
|
+
end
|
110
|
+
|
111
|
+
def watch_all(klass, except: [])
|
112
|
+
klass.public_instance_methods(false).each do |method_name|
|
113
|
+
next if except.include?(method_name)
|
114
|
+
watch(klass, method_name, type: :instance)
|
115
|
+
end
|
116
|
+
|
117
|
+
klass.public_methods(false).each do |method_name|
|
118
|
+
next if except.include?(method_name)
|
119
|
+
watch(klass, method_name, type: :class)
|
120
|
+
end
|
103
121
|
end
|
104
122
|
|
105
123
|
def verify(record_hash)
|
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.
|
4
|
+
version: 1.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
@@ -30,6 +30,8 @@ extensions: []
|
|
30
30
|
extra_rdoc_files: []
|
31
31
|
files:
|
32
32
|
- lib/example/calculator.rb
|
33
|
+
- lib/example/class_methods.rb
|
34
|
+
- lib/example/kw_calculator.rb
|
33
35
|
- lib/stable.rb
|
34
36
|
- lib/stable/configuration.rb
|
35
37
|
- lib/stable/fact.rb
|