fixtury 1.0.0.beta5 → 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: 297aa8d54ad35f629cfb75dc8c7599660dc24393ad87b03de039ad8f4dfd691a
4
- data.tar.gz: c89efb954c5bebe6751628d22b29ecc4fb1fd61020d53d321b7e782e93608007
3
+ metadata.gz: fbbb9952c697ebe0db7cb60e4fde3f3a24933200ad88f3ca13ba1d66f67af898
4
+ data.tar.gz: 81811a758a2b6384287dba64997ed5097a39214d1357640725d6e85a191023a8
5
5
  SHA512:
6
- metadata.gz: 9af1d90c107d075bfdf89c50ed59b59b0ae264a7799058bab495ae66f0e0451876c90d119e24219880d193f6dc6a869798cb7f568885a5b85e5f676f9871221d
7
- data.tar.gz: de852c51ecd2a53fa9ae050deea5d150fef75819c287330c831c99c9307b00ea98854e6c13df3dc9b03e5dd5119bf6805cee69a139199c22a0867b0a848d25ad
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.beta5)
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
@@ -94,11 +94,6 @@ module Fixtury
94
94
 
95
95
  pathnames.each do |pathname|
96
96
  method_name = (accessor_option == true ? pathname.split("/").last : accessor_option).to_sym
97
-
98
- if method_defined?(method_name)
99
- raise ArgumentError, "A method by the name of #{method_name} already exists in #{self}"
100
- end
101
-
102
97
  ivar = :"@fixtury_#{method_name}"
103
98
 
104
99
  class_eval <<-EV, __FILE__, __LINE__ + 1
@@ -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.beta5"
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.beta5
4
+ version: 1.0.0.beta7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson