factory_bot_instrumentation 1.3.0 → 1.4.0
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: 37442055c37286bda9ecc80137609a66e4170181350f1fe494e0140cf888a33c
|
4
|
+
data.tar.gz: eb684ed40aad5659818346b43b22510c981fac3283ce81239ff943b3148aa72b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c24c700505db37bd0960ccf4d4f941c9117c2b0885b15fbabe871ee7b63bd5d87b259e77a94e751784f9c51edb4d08c04f22ea6338ca4d0cf913475245d6f165
|
7
|
+
data.tar.gz: 20461fb181cd6e48fd3c7a32d5cfbc1f0647fb5a85095564c4cdeff3951a23b8a6047d6b60a532588f763222bb8475bac5ee8f0e27dd06d9fa6a20e40f3a07d4
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
* TODO: Replace this bullet point with an actual description of a change.
|
4
4
|
|
5
|
+
### 1.4.0 (6 January 2025)
|
6
|
+
|
7
|
+
* Moved the instrumentation methods (`#instrumentation`, `#scenarios`,
|
8
|
+
`#groups`, `#scenario_group`) from the `RootController` to the
|
9
|
+
`ApplicationController` (#23)
|
10
|
+
|
5
11
|
### 1.3.0 (3 January 2025)
|
6
12
|
|
7
13
|
* Raised minimum supported Ruby/Rails version to 2.7/6.1 (#22)
|
@@ -36,6 +36,53 @@ 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
|
39
86
|
end
|
40
87
|
end
|
41
88
|
end
|
@@ -79,53 +79,6 @@ 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
|
129
82
|
end
|
130
83
|
end
|
131
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_bot_instrumentation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hermann Mayer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot
|