fixtury 0.1.0.alpha → 0.1.0.alpha2
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/fixtury/errors/circular_dependency_error.rb +1 -1
- data/lib/fixtury/reference.rb +16 -0
- data/lib/fixtury/store.rb +15 -10
- data/lib/fixtury/version.rb +1 -1
- 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: 75498846db5af5a720586eee8dbd16a231b326ccbd3e11867235d048dd161aa1
|
4
|
+
data.tar.gz: 9205f55fed52ac282da960130416db10d8cf52c8a528e5b28b3ef2b94eccbc1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bb9a8d6f1cad6e929679f004e806d6160c25b195608cdaed9e3083120bb91ade8e3452710602f3311c5980b7a4d94f7179d8b411ca5a37bf7631c256e665690
|
7
|
+
data.tar.gz: da048dd34fc8e4d665bdf2c7b4fd5029ef15a2251a370aa014ae38799f9a15e9ff84ec65713ce5398d3f21dbebaa0f14884cea2185f0af7fddd3e25c0a237e48
|
data/lib/fixtury/reference.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fixtury
|
2
4
|
class Reference
|
3
5
|
|
6
|
+
HOLDER_VALUE = "__BUILDING_FIXTURE__"
|
7
|
+
|
8
|
+
def self.holder(name)
|
9
|
+
new(name, HOLDER_VALUE)
|
10
|
+
end
|
11
|
+
|
4
12
|
attr_reader :name, :value, :created_at
|
5
13
|
|
6
14
|
def initialize(name, value)
|
@@ -9,5 +17,13 @@ module Fixtury
|
|
9
17
|
@created_at = Time.now.to_i
|
10
18
|
end
|
11
19
|
|
20
|
+
def holder?
|
21
|
+
value == HOLDER_VALUE
|
22
|
+
end
|
23
|
+
|
24
|
+
def real?
|
25
|
+
!holder?
|
26
|
+
end
|
27
|
+
|
12
28
|
end
|
13
29
|
end
|
data/lib/fixtury/store.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "fileutils"
|
3
4
|
require "singleton"
|
4
5
|
require "yaml"
|
5
6
|
require "fixtury/locator"
|
@@ -12,8 +13,6 @@ module Fixtury
|
|
12
13
|
|
13
14
|
cattr_accessor :instance
|
14
15
|
|
15
|
-
HOLDER = "__BUILDING_FIXTURE__"
|
16
|
-
|
17
16
|
attr_reader :filepath, :references, :ttl, :auto_refresh_expired
|
18
17
|
attr_reader :schema, :locator
|
19
18
|
attr_reader :verbose
|
@@ -41,7 +40,13 @@ module Fixtury
|
|
41
40
|
def dump_to_file
|
42
41
|
return unless filepath
|
43
42
|
|
44
|
-
::File.
|
43
|
+
::FileUtils.mkdir_p(File.dirname(filepath))
|
44
|
+
|
45
|
+
writable = references.each_with_object({}) do |(full_name, ref), h|
|
46
|
+
h[full_name] = ref if ref.real?
|
47
|
+
end
|
48
|
+
|
49
|
+
::File.open(filepath, "wb") { |io| io.write(writable.to_yaml) }
|
45
50
|
end
|
46
51
|
|
47
52
|
def clear_expired_references!
|
@@ -59,7 +64,7 @@ module Fixtury
|
|
59
64
|
get(dfn.name)
|
60
65
|
end
|
61
66
|
|
62
|
-
schema.
|
67
|
+
schema.children.each_pair do |_key, ns|
|
63
68
|
load_all(ns)
|
64
69
|
end
|
65
70
|
end
|
@@ -89,7 +94,7 @@ module Fixtury
|
|
89
94
|
dfn = schema.get_definition!(name)
|
90
95
|
full_name = dfn.name
|
91
96
|
ref = references[full_name]
|
92
|
-
result = ref
|
97
|
+
result = ref&.real?
|
93
98
|
log { result ? "hit #{full_name}" : "miss #{full_name}" }
|
94
99
|
result
|
95
100
|
end
|
@@ -99,13 +104,13 @@ module Fixtury
|
|
99
104
|
full_name = dfn.name
|
100
105
|
ref = references[full_name]
|
101
106
|
|
102
|
-
if ref
|
107
|
+
if ref&.holder?
|
103
108
|
raise ::Fixtury::Errors::CircularDependencyError, full_name
|
104
109
|
end
|
105
110
|
|
106
111
|
if ref && auto_refresh_expired && ref_expired?(ref)
|
107
112
|
log { "refreshing #{full_name}" }
|
108
|
-
clear_ref(
|
113
|
+
clear_ref(full_name)
|
109
114
|
ref = nil
|
110
115
|
end
|
111
116
|
|
@@ -114,15 +119,15 @@ module Fixtury
|
|
114
119
|
if ref
|
115
120
|
log { "hit #{full_name}" }
|
116
121
|
value = load_ref(ref.value)
|
117
|
-
|
122
|
+
if value.nil?
|
118
123
|
clear_ref(full_name)
|
119
124
|
log { "missing #{full_name}" }
|
120
125
|
end
|
121
126
|
end
|
122
127
|
|
123
128
|
if value.nil?
|
124
|
-
# set the references to
|
125
|
-
references[full_name] =
|
129
|
+
# set the references to a holder value so any recursive behavior ends up hitting a circular dependency error if the same fixture load is attempted
|
130
|
+
references[full_name] = ::Fixtury::Reference.holder(full_name)
|
126
131
|
|
127
132
|
value = dfn.call(store: self, execution_context: execution_context)
|
128
133
|
|
data/lib/fixtury/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixtury
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01
|
11
|
+
date: 2020-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: autotest
|