maintenance_tasks 2.5.0 → 2.5.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: f26c6afe0c4b45b6d191162ab2c37e3b058e8b6ae473b17cfc3724e29e638fce
4
- data.tar.gz: 4308f3356279fa5879429077cb482d91033336bfa62c1c4afb51fc9d957b1785
3
+ metadata.gz: 8952908cba45fd0a79cfcf0d334e89eab4e3a554ba4c0b1acffb318c7e92730f
4
+ data.tar.gz: bc1312f6269c51fe80480f7af90281c89c36bc9c78f052f65f4b5853effa5a41
5
5
  SHA512:
6
- metadata.gz: 383bc985f1a465e00889b20997d5718ff2039d5cdc6ca6b14a427a183fef4df3ff445eda2893d10b41d0bf243a6150ad5699afdfcbe3beaf280e4d35f130c1f5
7
- data.tar.gz: d2b54c567a3d89e78f3538ca22b35d83dcb150e7520fc3014aa2040836f2e2741eb2bda700211c6411b8355b54ee19814655cf79827358d2d2f922fa855934af
6
+ metadata.gz: c32f23abae224617aef9148ac7e890a95fb799997e0900b6a5ad72fbb988cadb25ef61ef6a35e803f2483cce93f6ad20d379c202f2a513f72c339d553e830a12
7
+ data.tar.gz: cead5f36f1038614e23da3c6fa3661be58d00ac326a859681a3740d818977f0c3c311860f567d96701dcd04bc1019e001ad0903c20833444b2a0669dd9aac6e9
@@ -101,16 +101,31 @@ module MaintenanceTasks
101
101
  )
102
102
  end
103
103
 
104
- # Return the appropriate field tag for the parameter, based on its type.
105
- # If the parameter has a `validates_inclusion_of` validator, return a dropdown list of options instead.
106
- def parameter_field(form_builder, parameter_name)
107
- inclusion_validator = form_builder.object.class.validators_on(parameter_name).find do |validator|
104
+ # Resolves values covered by the inclusion validator for a task attribute.
105
+ # Only Arrays are supported, option types such as:
106
+ # Procs, lambdas, symbols, and Range are not supported and return nil.
107
+ #
108
+ # Returned values are used to populate a dropdown list of options.
109
+ #
110
+ # @param task_class [Class<Task>] The task class for which the value needs to be resolved.
111
+ # @param parameter_name [String] The parameter name.
112
+ #
113
+ # @return [Array] value of the resolved inclusion option.
114
+ def resolve_inclusion_value(task_class, parameter_name)
115
+ inclusion_validator = task_class.validators_on(parameter_name).find do |validator|
108
116
  validator.kind == :inclusion
109
117
  end
118
+ return unless inclusion_validator
110
119
 
111
- return form_builder.select(
112
- parameter_name, inclusion_validator.options[:in], prompt: "Select a value"
113
- ) if inclusion_validator
120
+ in_option = inclusion_validator.options[:in] || inclusion_validator.options[:within]
121
+ in_option if in_option.is_a?(Array)
122
+ end
123
+
124
+ # Return the appropriate field tag for the parameter, based on its type.
125
+ # If the parameter has a `validates_inclusion_of` validator, return a dropdown list of options instead.
126
+ def parameter_field(form_builder, parameter_name)
127
+ inclusion_values = resolve_inclusion_value(form_builder.object.class, parameter_name)
128
+ return form_builder.select(parameter_name, inclusion_values, prompt: "Select a value") if inclusion_values
114
129
 
115
130
  case form_builder.object.class.attribute_types[parameter_name]
116
131
  when ActiveModel::Type::Integer
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maintenance_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Engineering
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-31 00:00:00.000000000 Z
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -171,7 +171,7 @@ homepage: https://github.com/Shopify/maintenance_tasks
171
171
  licenses:
172
172
  - MIT
173
173
  metadata:
174
- source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v2.5.0
174
+ source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v2.5.1
175
175
  allowed_push_host: https://rubygems.org
176
176
  post_install_message:
177
177
  rdoc_options: []
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
190
  requirements: []
191
- rubygems_version: 3.5.5
191
+ rubygems_version: 3.5.6
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: A Rails engine for queuing and managing maintenance tasks