stable 1.4.0 → 1.5.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: c0ceeb4f1149e27df669ab25482efd557e1235a1e55014322ada67ce1639c34f
4
- data.tar.gz: 2e181545071d2d064cea2da6ebe1c587e113af4751333a20af2260b413ce602e
3
+ metadata.gz: 449e9c176cb2085bca88f353966805090e49d1cb8292966069fc4ca32bb18fde
4
+ data.tar.gz: 48980832cbe61ac2dc13474eae12bd70e4bd5c6e42d015eac8ae28245b34ccd4
5
5
  SHA512:
6
- metadata.gz: 79c8dd17e53a71b7b4ee2a045182c08aa8c85a08f5aca4374aca987ef7ab740e134776fd1b0f396462e5e9890713639c7581b332eab507ca295c71c2854e3985
7
- data.tar.gz: 0ecb7350223103b539f01a260219549b75c9f0602abb7369ac57cd92aba6f76cdc060371d7d0ef0f0037fdc8552501ffd54db5758626d5a8b2b55e1b0bf768e2
6
+ metadata.gz: dac85ffc0a8efbd42ea82b62f8ba1796e810c60f7536060ced002c0f6c184d308374b012d8e4d2b30ae3706522a1b4642919fa8447c0b3fe4f3cb2c4516ef483
7
+ data.tar.gz: 491c78e463ac466fb08cf60c0437f4a99b6df645aa7c2537394a4e470d3707d06244a86154eaf7f94726ee5af2f3747bbbb98c8c7e5eae2bd3f67e04580867d9
@@ -0,0 +1,11 @@
1
+ # lib/stable/configuration.rb
2
+ module Stable
3
+ class Configuration
4
+ attr_accessor :storage_path, :enabled
5
+
6
+ def initialize
7
+ @storage_path = nil
8
+ @enabled = false
9
+ end
10
+ end
11
+ end
data/lib/stable.rb CHANGED
@@ -1,9 +1,18 @@
1
1
  # `stable` is a library for recording and replaying method calls.
2
2
  # See README.md for detailed usage instructions.
3
3
  require_relative 'stable/spec'
4
+ require_relative 'stable/configuration'
4
5
 
5
6
  module Stable
6
7
  class << self
8
+ def configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def configure
13
+ yield(configuration)
14
+ end
15
+
7
16
  def enable!
8
17
  Thread.current[:stable_enabled] = true
9
18
  end
@@ -13,7 +22,7 @@ module Stable
13
22
  end
14
23
 
15
24
  def enabled?
16
- Thread.current[:stable_enabled] || false
25
+ Thread.current[:stable_enabled] || configuration.enabled || false
17
26
  end
18
27
 
19
28
  def storage=(io)
@@ -21,7 +30,7 @@ module Stable
21
30
  end
22
31
 
23
32
  def storage
24
- @storage || raise("Stable.storage must be set to an IO-like object")
33
+ @storage ||= (configuration.storage_path && File.open(configuration.storage_path, 'a+')) || raise("Stable.storage must be set to an IO-like object")
25
34
  end
26
35
 
27
36
  # this method is a block-based way to enable and disable recording of
@@ -39,6 +48,8 @@ module Stable
39
48
  yield if block_given?
40
49
  ensure
41
50
  disable!
51
+ storage.close if storage.respond_to?(:close)
52
+ @storage = nil
42
53
  end
43
54
 
44
55
  def watch(klass, method_name)
@@ -56,6 +67,7 @@ module Stable
56
67
  )
57
68
  unless Stable.send(:_spec_exists?, spec.signature)
58
69
  Stable.storage.puts(spec.to_jsonl)
70
+ Stable.storage.flush
59
71
  Stable.send(:_recorded_specs) << spec
60
72
  end
61
73
  result
@@ -72,6 +84,7 @@ module Stable
72
84
  )
73
85
  unless Stable.send(:_spec_exists?, spec.signature)
74
86
  Stable.storage.puts(spec.to_jsonl)
87
+ Stable.storage.flush
75
88
  Stable.send(:_recorded_specs) << spec
76
89
  end
77
90
  raise e
@@ -93,7 +106,10 @@ module Stable
93
106
  def _recorded_specs
94
107
  @_recorded_specs ||= begin
95
108
  return [] unless storage.respond_to?(:path) && File.exist?(storage.path)
96
- File.foreach(storage.path).map { |line| Spec.from_jsonl(line) }
109
+ storage.rewind
110
+ specs = storage.each_line.map { |line| Spec.from_jsonl(line) }
111
+ storage.seek(0, IO::SEEK_END)
112
+ specs
97
113
  end
98
114
  end
99
115
 
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.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
@@ -17,6 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/stable.rb
20
+ - lib/stable/configuration.rb
20
21
  - lib/stable/spec.rb
21
22
  homepage: https://github.com/jefflunt/stable
22
23
  licenses: