stable 1.9.1 → 1.11.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/stable/configuration.rb +2 -1
- data/lib/stable/{spec.rb → fact.rb} +3 -3
- data/lib/stable.rb +17 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c63954061bcff73999b7e9a5f25bf55b9ea34d500115ed04f8de051df574c421
|
4
|
+
data.tar.gz: 110a450c56f126c1244bccaeb0c5b02f684ca87930d1fc6781a86001089dbe46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdfe098ba1a24a3d73b739cb8ebd446db8d6331e9960d8db1cc15b5ed80f65b0549b14acaf092bfa2c071254c16c58fdac26d21d6b09588c9a8310f04b4806a0
|
7
|
+
data.tar.gz: e3c930ef2fc5e37a6773c83abfcc4ec2344c4b5a5c5abea6c006de7504fe20232c49265eaf881b6dd531f8ed1bb37550e60de312d6da59e66be8901f0176dee5
|
data/lib/stable/configuration.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# lib/stable/configuration.rb
|
2
2
|
module Stable
|
3
3
|
class Configuration
|
4
|
-
attr_accessor :storage_path, :enabled
|
4
|
+
attr_accessor :storage_path, :enabled, :fact_paths
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@storage_path = nil
|
8
8
|
@enabled = false
|
9
|
+
@fact_paths = ['facts/**/*.fact']
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
# lib/stable/
|
1
|
+
# lib/stable/fact.rb
|
2
2
|
require 'json'
|
3
3
|
require 'securerandom'
|
4
4
|
require 'digest'
|
5
5
|
|
6
6
|
module Stable
|
7
|
-
# a
|
7
|
+
# a fact is a recording of a single method call, including the inputs and
|
8
8
|
# outputs. it's a self-contained, serializable representation of a method's
|
9
9
|
# behavior at a specific point in time.
|
10
|
-
class
|
10
|
+
class Fact
|
11
11
|
attr_reader :class_name, :method_name, :args, :result, :error, :actual_result, :actual_error, :status, :uuid, :signature, :name
|
12
12
|
|
13
13
|
def initialize(class_name:, method_name:, args:, result: nil, error: nil, uuid: SecureRandom.uuid, name: nil)
|
data/lib/stable.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# `stable` is a library for recording and replaying method calls.
|
2
2
|
# See README.md for detailed usage instructions.
|
3
|
-
require_relative 'stable/
|
3
|
+
require_relative 'stable/fact'
|
4
4
|
require_relative 'stable/configuration'
|
5
5
|
|
6
6
|
if defined?(Rake)
|
@@ -38,7 +38,7 @@ module Stable
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# this method is a block-based way to enable and disable recording of
|
41
|
-
#
|
41
|
+
# facts. It ensures that recording is turned on for the duration of the
|
42
42
|
# block and is automatically turned off afterward, even if an error occurs.
|
43
43
|
#
|
44
44
|
# example:
|
@@ -63,20 +63,20 @@ module Stable
|
|
63
63
|
if Stable.enabled?
|
64
64
|
begin
|
65
65
|
result = original_method.bind(self).call(*args, &block)
|
66
|
-
|
66
|
+
fact = Fact.new(
|
67
67
|
class_name: klass.name,
|
68
68
|
method_name: method_name,
|
69
69
|
args: args,
|
70
70
|
result: result
|
71
71
|
)
|
72
|
-
unless Stable.send(:
|
73
|
-
Stable.storage.puts(
|
72
|
+
unless Stable.send(:_fact_exists?, fact.signature)
|
73
|
+
Stable.storage.puts(fact.to_jsonl)
|
74
74
|
Stable.storage.flush
|
75
|
-
Stable.send(:
|
75
|
+
Stable.send(:_recorded_facts) << fact
|
76
76
|
end
|
77
77
|
result
|
78
78
|
rescue => e
|
79
|
-
|
79
|
+
fact = Fact.new(
|
80
80
|
class_name: klass.name,
|
81
81
|
method_name: method_name,
|
82
82
|
args: args,
|
@@ -86,10 +86,10 @@ module Stable
|
|
86
86
|
backtrace: e.backtrace
|
87
87
|
}
|
88
88
|
)
|
89
|
-
unless Stable.send(:
|
90
|
-
Stable.storage.puts(
|
89
|
+
unless Stable.send(:_fact_exists?, fact.signature)
|
90
|
+
Stable.storage.puts(fact.to_jsonl)
|
91
91
|
Stable.storage.flush
|
92
|
-
Stable.send(:
|
92
|
+
Stable.send(:_recorded_facts) << fact
|
93
93
|
end
|
94
94
|
raise e
|
95
95
|
end
|
@@ -102,23 +102,23 @@ module Stable
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def verify(record_hash)
|
105
|
-
|
105
|
+
Fact.from_jsonl(record_hash.to_json).run!
|
106
106
|
end
|
107
107
|
|
108
108
|
private
|
109
109
|
|
110
|
-
def
|
111
|
-
@
|
110
|
+
def _recorded_facts
|
111
|
+
@_recorded_facts ||= begin
|
112
112
|
return [] unless storage.respond_to?(:path) && File.exist?(storage.path)
|
113
113
|
storage.rewind
|
114
|
-
|
114
|
+
facts = storage.each_line.map { |line| Fact.from_jsonl(line) }
|
115
115
|
storage.seek(0, IO::SEEK_END)
|
116
|
-
|
116
|
+
facts
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
def
|
121
|
-
|
120
|
+
def _fact_exists?(signature)
|
121
|
+
_recorded_facts.any? { |fact| fact.signature == signature }
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
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.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
@@ -33,7 +33,7 @@ files:
|
|
33
33
|
- lib/example/calculator.rb
|
34
34
|
- lib/stable.rb
|
35
35
|
- lib/stable/configuration.rb
|
36
|
-
- lib/stable/
|
36
|
+
- lib/stable/fact.rb
|
37
37
|
homepage: https://github.com/jefflunt/stable
|
38
38
|
licenses:
|
39
39
|
- MIT
|