factory_bot_instrumentation 1.4.0 → 1.4.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d643a4b86dc1bca8a7df314258f1fee44afa9caa0f20efd84dc5694e549249da
|
4
|
+
data.tar.gz: 12ad4d38793d3ecc33b5588070940a852ddd22ed1ae1a51a67773141f24fb14d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea18bccad8065d7b71dc50058e7ba73d970e935d8fc14bb30f2b4126e31685b64938e023d75cbab28a809414dc7d1628a1b6e0396490584c7d9f5c344b582723
|
7
|
+
data.tar.gz: 26df3f123614f34d35197c305ddcda4f83a8cfb9855ced96b2917ae3a95b8f724e8fee041f48b1c57ad5082158fba05e2160edbb34f82237f8846c7e6c5b37b7
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
* TODO: Replace this bullet point with an actual description of a change.
|
4
4
|
|
5
|
+
### 1.4.1 (6 January 2025)
|
6
|
+
|
7
|
+
* Reverted (#23) as it causes errors for unknown reasons
|
8
|
+
|
5
9
|
### 1.4.0 (6 January 2025)
|
6
10
|
|
7
11
|
* Moved the instrumentation methods (`#instrumentation`, `#scenarios`,
|
@@ -36,53 +36,6 @@ module FactoryBot
|
|
36
36
|
)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
40
|
-
# Unfortunately +Rails.configuration.instrumentation+ is only read once
|
41
|
-
# and do not hot-reload on changes. Thats why we read this file manually
|
42
|
-
# to get always a fresh state.
|
43
|
-
#
|
44
|
-
# @return [Hash{String => Mixed}] the instrumentation scenarios
|
45
|
-
def instrumentation
|
46
|
-
config_file = FactoryBot::Instrumentation.configuration.config_file.to_s
|
47
|
-
template = ERB.new(Pathname.new(config_file).read)
|
48
|
-
load_method = YAML.respond_to?(:unsafe_load) ? :unsafe_load : :load
|
49
|
-
YAML.send(load_method, template.result(binding))[Rails.env] || {}
|
50
|
-
end
|
51
|
-
|
52
|
-
# Map all the instrumentation scenarios into groups and pass them back.
|
53
|
-
#
|
54
|
-
# @return [Hash{String => Array}] the grouped scenarios
|
55
|
-
def scenarios
|
56
|
-
res = instrumentation['scenarios'] || []
|
57
|
-
res.each_with_object({}) do |scenario, memo|
|
58
|
-
group = scenario_group(scenario['name'])
|
59
|
-
scenario['group'] = group
|
60
|
-
memo[group] = [] unless memo.key? group
|
61
|
-
memo[group] << scenario
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Map all the configured scenario groups to a useable hash.
|
66
|
-
#
|
67
|
-
# @return [Hash{Regexp => String}] the group mapping
|
68
|
-
def groups
|
69
|
-
(instrumentation['groups'] || {}).transform_keys do |key|
|
70
|
-
Regexp.new(Regexp.quote(key))
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# Fetch the group name for a given scenario name. This will utilize the
|
75
|
-
# +SCENARIO_GROUPS+ map.
|
76
|
-
#
|
77
|
-
# @param name [String] the scenario name
|
78
|
-
# @return [String] the group name
|
79
|
-
def scenario_group(name)
|
80
|
-
groups.map do |pattern, group_name|
|
81
|
-
next unless pattern.match? name
|
82
|
-
|
83
|
-
group_name
|
84
|
-
end.compact.first || 'Various'
|
85
|
-
end
|
86
39
|
end
|
87
40
|
end
|
88
41
|
end
|
@@ -79,6 +79,53 @@ module FactoryBot
|
|
79
79
|
]
|
80
80
|
end
|
81
81
|
# rubocop:enable Metrics/MethodLength
|
82
|
+
|
83
|
+
# Unfortunately +Rails.configuration.instrumentation+ is only read once
|
84
|
+
# and do not hot-reload on changes. Thats why we read this file manually
|
85
|
+
# to get always a fresh state.
|
86
|
+
#
|
87
|
+
# @return [Hash{String => Mixed}] the instrumentation scenarios
|
88
|
+
def instrumentation
|
89
|
+
config_file = FactoryBot::Instrumentation.configuration.config_file.to_s
|
90
|
+
template = ERB.new(Pathname.new(config_file).read)
|
91
|
+
load_method = YAML.respond_to?(:unsafe_load) ? :unsafe_load : :load
|
92
|
+
YAML.send(load_method, template.result(binding))[Rails.env] || {}
|
93
|
+
end
|
94
|
+
|
95
|
+
# Map all the instrumentation scenarios into groups and pass them back.
|
96
|
+
#
|
97
|
+
# @return [Hash{String => Array}] the grouped scenarios
|
98
|
+
def scenarios
|
99
|
+
res = instrumentation['scenarios'] || []
|
100
|
+
res.each_with_object({}) do |scenario, memo|
|
101
|
+
group = scenario_group(scenario['name'])
|
102
|
+
scenario['group'] = group
|
103
|
+
memo[group] = [] unless memo.key? group
|
104
|
+
memo[group] << scenario
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Map all the configured scenario groups to a useable hash.
|
109
|
+
#
|
110
|
+
# @return [Hash{Regexp => String}] the group mapping
|
111
|
+
def groups
|
112
|
+
(instrumentation['groups'] || {}).transform_keys do |key|
|
113
|
+
Regexp.new(Regexp.quote(key))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Fetch the group name for a given scenario name. This will utilize the
|
118
|
+
# +SCENARIO_GROUPS+ map.
|
119
|
+
#
|
120
|
+
# @param name [String] the scenario name
|
121
|
+
# @return [String] the group name
|
122
|
+
def scenario_group(name)
|
123
|
+
groups.map do |pattern, group_name|
|
124
|
+
next unless pattern.match? name
|
125
|
+
|
126
|
+
group_name
|
127
|
+
end.compact.first || 'Various'
|
128
|
+
end
|
82
129
|
end
|
83
130
|
end
|
84
131
|
end
|