fixtury 1.0.0.beta6 → 1.0.0.beta7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 549d52f7830e397113098a883ce5086c2170cd02b4afc4f17f4b1fc6369076cb
4
- data.tar.gz: 625a595982202950245e1804011aba787945d9a8c5cf1127f676c9112ae6b41e
3
+ metadata.gz: fbbb9952c697ebe0db7cb60e4fde3f3a24933200ad88f3ca13ba1d66f67af898
4
+ data.tar.gz: 81811a758a2b6384287dba64997ed5097a39214d1357640725d6e85a191023a8
5
5
  SHA512:
6
- metadata.gz: 44906dd01d66b02ffeada31d11bcb40531aa4ee66f56b7f6bd3f21dc84291c26d5f32d7715e19467ca5611df0aba77716e1c62dcf8e9fcec60121550eb33b4ac
7
- data.tar.gz: 717d96c8e0a72891946c0e3a7faacc3646c100468481eae7d776856e9a1f40ac3ec768df2aa8dcf8d16c805f1435796249545ae576a053306a1547fcbd45c8a9
6
+ metadata.gz: c25d11f8cc41d4ebcb93b1d597d357619ebcf6e419b3a83a9fe0659c5b5cc34ec486aed5195c74b9dbc04963b55d55c1956b5a652eccf8992d60611d478cbadb
7
+ data.tar.gz: 586c0512f4f470b816e0307aff6b6e22d9eb11e7271be292d73579023811ad671898de8b0c5ffd47557da61e1fc1bf61e54ec0884265ebd5531c2e9fac0255a5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fixtury (1.0.0.beta6)
4
+ fixtury (1.0.0.beta7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- attr_reader :value, :definition, :store
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
- @value = nil
25
+ @output = Output.new
13
26
  end
14
27
 
15
28
  def call
16
29
  run_definition
17
- value
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
- @value = if callable.arity.positive?
41
+ if callable.arity.positive?
29
42
  deps = build_dependency_store
30
- ::Fixtury.hooks.call(:execution, self) do
43
+ around_execution do
31
44
  instance_exec(deps, &callable)
32
45
  end
33
46
  else
34
- ::Fixtury.hooks.call(:execution, self) do
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
@@ -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, :options
18
+ attr_reader :name, :locator_key, :created_at, :metadata
19
+ alias options metadata # backwards compatibility
19
20
 
20
- def initialize(name, locator_key, **options)
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
- @options = options
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
- value = executor.call
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,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fixtury
4
4
 
5
- VERSION = "1.0.0.beta6"
5
+ VERSION = "1.0.0.beta7"
6
6
 
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixtury
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta6
4
+ version: 1.0.0.beta7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson