fixtury 1.0.0.beta6 → 1.0.0.beta7
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/Gemfile.lock +1 -1
- data/lib/fixtury/definition_executor.rb +29 -6
- data/lib/fixtury/reference.rb +4 -3
- data/lib/fixtury/store.rb +4 -2
- data/lib/fixtury/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbbb9952c697ebe0db7cb60e4fde3f3a24933200ad88f3ca13ba1d66f67af898
|
4
|
+
data.tar.gz: 81811a758a2b6384287dba64997ed5097a39214d1357640725d6e85a191023a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c25d11f8cc41d4ebcb93b1d597d357619ebcf6e419b3a83a9fe0659c5b5cc34ec486aed5195c74b9dbc04963b55d55c1956b5a652eccf8992d60611d478cbadb
|
7
|
+
data.tar.gz: 586c0512f4f470b816e0307aff6b6e22d9eb11e7271be292d73579023811ad671898de8b0c5ffd47557da61e1fc1bf61e54ec0884265ebd5531c2e9fac0255a5
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "benchmark"
|
4
|
+
|
3
5
|
module Fixtury
|
4
6
|
# A container that manages the execution of a definition in the context of a store.
|
5
7
|
class DefinitionExecutor
|
6
8
|
|
7
|
-
|
9
|
+
class Output
|
10
|
+
|
11
|
+
attr_accessor :value, :metadata
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@value = nil
|
15
|
+
@metadata = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :output, :definition, :store
|
8
21
|
|
9
22
|
def initialize(store: nil, definition:)
|
10
23
|
@store = store
|
11
24
|
@definition = definition
|
12
|
-
@
|
25
|
+
@output = Output.new
|
13
26
|
end
|
14
27
|
|
15
28
|
def call
|
16
29
|
run_definition
|
17
|
-
|
30
|
+
output
|
18
31
|
end
|
19
32
|
|
20
33
|
private
|
@@ -25,13 +38,13 @@ module Fixtury
|
|
25
38
|
def run_definition
|
26
39
|
callable = definition.callable
|
27
40
|
|
28
|
-
|
41
|
+
if callable.arity.positive?
|
29
42
|
deps = build_dependency_store
|
30
|
-
|
43
|
+
around_execution do
|
31
44
|
instance_exec(deps, &callable)
|
32
45
|
end
|
33
46
|
else
|
34
|
-
|
47
|
+
around_execution do
|
35
48
|
instance_eval(&callable)
|
36
49
|
end
|
37
50
|
end
|
@@ -41,6 +54,16 @@ module Fixtury
|
|
41
54
|
raise Errors::DefinitionExecutionError.new(definition.pathname, e)
|
42
55
|
end
|
43
56
|
|
57
|
+
def around_execution(&block)
|
58
|
+
measure_timing do
|
59
|
+
@output.value = ::Fixtury.hooks.call(:execution, self, &block)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def measure_timing(&block)
|
64
|
+
@output.metadata[:duration] = Benchmark.realtime(&block)
|
65
|
+
end
|
66
|
+
|
44
67
|
def build_dependency_store
|
45
68
|
DependencyStore.new(definition: definition, store: store)
|
46
69
|
end
|
data/lib/fixtury/reference.rb
CHANGED
@@ -15,13 +15,14 @@ module Fixtury
|
|
15
15
|
new(name, HOLDER_KEY)
|
16
16
|
end
|
17
17
|
|
18
|
-
attr_reader :name, :locator_key, :created_at, :
|
18
|
+
attr_reader :name, :locator_key, :created_at, :metadata
|
19
|
+
alias options metadata # backwards compatibility
|
19
20
|
|
20
|
-
def initialize(name, locator_key, **
|
21
|
+
def initialize(name, locator_key, **metadata)
|
21
22
|
@name = name
|
22
23
|
@locator_key = locator_key
|
23
24
|
@created_at = Time.now.to_i
|
24
|
-
@
|
25
|
+
@metadata = metadata
|
25
26
|
end
|
26
27
|
|
27
28
|
def holder?
|
data/lib/fixtury/store.rb
CHANGED
@@ -159,7 +159,8 @@ module Fixtury
|
|
159
159
|
|
160
160
|
begin
|
161
161
|
executor = ::Fixtury::DefinitionExecutor.new(store: self, definition: dfn)
|
162
|
-
|
162
|
+
output = executor.call
|
163
|
+
value = output.value
|
163
164
|
rescue StandardError
|
164
165
|
clear_reference(pathname)
|
165
166
|
raise
|
@@ -167,8 +168,9 @@ module Fixtury
|
|
167
168
|
|
168
169
|
log("store #{pathname}", level: LOG_LEVEL_DEBUG)
|
169
170
|
|
170
|
-
locator_key = locator.dump(value, context: pathname)
|
171
|
+
locator_key = locator.dump(output.value, context: pathname)
|
171
172
|
reference_opts = {}
|
173
|
+
reference_opts.merge!(output.metadata)
|
172
174
|
reference_opts[:isolation_key] = isokey unless isokey == pathname
|
173
175
|
references[pathname] = ::Fixtury::Reference.new(
|
174
176
|
pathname,
|
data/lib/fixtury/version.rb
CHANGED