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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba835113f891ef233758d210388aa98c40713d5cd3f959f22bb6863007c35923
4
- data.tar.gz: 1c4b639f56e3f711a3325ec071e059b7b6a666399e17cb346560539bbaaba330
3
+ metadata.gz: c63954061bcff73999b7e9a5f25bf55b9ea34d500115ed04f8de051df574c421
4
+ data.tar.gz: 110a450c56f126c1244bccaeb0c5b02f684ca87930d1fc6781a86001089dbe46
5
5
  SHA512:
6
- metadata.gz: 767b778129e795db14926a767e0658cb17fd779b2fa5fdc8fe962939a86817956509661099a65f87d62075052d974e30eb07bab0082256bff54506018f6a9c79
7
- data.tar.gz: c00fc59dbd7f6240bee2a359bb3cf9500ca00bc4adb0ab58d0644a417a71be4db98a51bd02b4801ece007d72eac908c34415370051a69b76cd7b1f4920ee0027
6
+ metadata.gz: cdfe098ba1a24a3d73b739cb8ebd446db8d6331e9960d8db1cc15b5ed80f65b0549b14acaf092bfa2c071254c16c58fdac26d21d6b09588c9a8310f04b4806a0
7
+ data.tar.gz: e3c930ef2fc5e37a6773c83abfcc4ec2344c4b5a5c5abea6c006de7504fe20232c49265eaf881b6dd531f8ed1bb37550e60de312d6da59e66be8901f0176dee5
@@ -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/spec.rb
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 spec is a recording of a single method call, including the inputs and
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 Spec
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/spec'
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
- # specs. It ensures that recording is turned on for the duration of the
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
- spec = Spec.new(
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(:_spec_exists?, spec.signature)
73
- Stable.storage.puts(spec.to_jsonl)
72
+ unless Stable.send(:_fact_exists?, fact.signature)
73
+ Stable.storage.puts(fact.to_jsonl)
74
74
  Stable.storage.flush
75
- Stable.send(:_recorded_specs) << spec
75
+ Stable.send(:_recorded_facts) << fact
76
76
  end
77
77
  result
78
78
  rescue => e
79
- spec = Spec.new(
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(:_spec_exists?, spec.signature)
90
- Stable.storage.puts(spec.to_jsonl)
89
+ unless Stable.send(:_fact_exists?, fact.signature)
90
+ Stable.storage.puts(fact.to_jsonl)
91
91
  Stable.storage.flush
92
- Stable.send(:_recorded_specs) << spec
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
- Spec.from_jsonl(record_hash.to_json).run!
105
+ Fact.from_jsonl(record_hash.to_json).run!
106
106
  end
107
107
 
108
108
  private
109
109
 
110
- def _recorded_specs
111
- @_recorded_specs ||= begin
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
- specs = storage.each_line.map { |line| Spec.from_jsonl(line) }
114
+ facts = storage.each_line.map { |line| Fact.from_jsonl(line) }
115
115
  storage.seek(0, IO::SEEK_END)
116
- specs
116
+ facts
117
117
  end
118
118
  end
119
119
 
120
- def _spec_exists?(signature)
121
- _recorded_specs.any? { |spec| spec.signature == signature }
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.9.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/spec.rb
36
+ - lib/stable/fact.rb
37
37
  homepage: https://github.com/jefflunt/stable
38
38
  licenses:
39
39
  - MIT