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: f20a85c36ecf45c108f2a5a8e95d2b31a1cd9d6d2b0b6e25215d813eca64b2bb
4
- data.tar.gz: 580b377842ccfb58d4c2285730eada5492f8c6bc9f973e9cb5548cdd3dbadc17
3
+ metadata.gz: 37442055c37286bda9ecc80137609a66e4170181350f1fe494e0140cf888a33c
4
+ data.tar.gz: eb684ed40aad5659818346b43b22510c981fac3283ce81239ff943b3148aa72b
5
5
  SHA512:
6
- metadata.gz: a2558f36f7ac6008f7d3daa7a542ab968efc28f78cad5780310a2e26dceff9715162766eb3ac956503988e8ca3c817f25c8a679c182fc9c1944f4b5b81293611
7
- data.tar.gz: 12580bfe12910573ab0bf0f3a26dcabe4ad47dde6e8bb481bab04da2d943fda2c9df70fc416651442b84a1a4b4f87ab1bc41eb077df88ef90f3e0b83a9788b8f
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
@@ -4,7 +4,7 @@ module FactoryBot
4
4
  # The gem version details.
5
5
  module Instrumentation
6
6
  # The version of the +factory_bot_instrumentation+ gem
7
- VERSION = '1.3.0'
7
+ VERSION = '1.4.0'
8
8
 
9
9
  class << self
10
10
  # Returns the version of gem as a string.
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.3.0
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-03 00:00:00.000000000 Z
11
+ date: 2025-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot