cmdx 1.1.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.cursor/prompts/docs.md +4 -1
- data/.cursor/prompts/llms.md +20 -0
- data/.cursor/prompts/rspec.md +4 -1
- data/.cursor/prompts/yardoc.md +3 -2
- data/.cursor/rules/cursor-instructions.mdc +56 -1
- data/.irbrc +6 -0
- data/.rubocop.yml +29 -18
- data/.ruby-version +1 -1
- data/CHANGELOG.md +6 -128
- data/LLM.md +3317 -0
- data/README.md +68 -44
- data/docs/attributes/coercions.md +162 -0
- data/docs/attributes/defaults.md +90 -0
- data/docs/attributes/definitions.md +281 -0
- data/docs/attributes/naming.md +78 -0
- data/docs/attributes/validations.md +309 -0
- data/docs/basics/chain.md +56 -249
- data/docs/basics/context.md +56 -289
- data/docs/basics/execution.md +114 -0
- data/docs/basics/setup.md +37 -334
- data/docs/callbacks.md +89 -467
- data/docs/deprecation.md +91 -174
- data/docs/getting_started.md +212 -202
- data/docs/internationalization.md +11 -647
- data/docs/interruptions/exceptions.md +23 -198
- data/docs/interruptions/faults.md +71 -151
- data/docs/interruptions/halt.md +109 -186
- data/docs/logging.md +44 -256
- data/docs/middlewares.md +113 -426
- data/docs/outcomes/result.md +81 -228
- data/docs/outcomes/states.md +33 -221
- data/docs/outcomes/statuses.md +21 -311
- data/docs/tips_and_tricks.md +120 -70
- data/docs/workflows.md +99 -283
- data/lib/cmdx/.DS_Store +0 -0
- data/lib/cmdx/attribute.rb +229 -0
- data/lib/cmdx/attribute_registry.rb +94 -0
- data/lib/cmdx/attribute_value.rb +193 -0
- data/lib/cmdx/callback_registry.rb +69 -77
- data/lib/cmdx/chain.rb +56 -73
- data/lib/cmdx/coercion_registry.rb +52 -68
- data/lib/cmdx/coercions/array.rb +19 -18
- data/lib/cmdx/coercions/big_decimal.rb +20 -24
- data/lib/cmdx/coercions/boolean.rb +26 -25
- data/lib/cmdx/coercions/complex.rb +21 -22
- data/lib/cmdx/coercions/date.rb +25 -23
- data/lib/cmdx/coercions/date_time.rb +24 -25
- data/lib/cmdx/coercions/float.rb +25 -22
- data/lib/cmdx/coercions/hash.rb +31 -32
- data/lib/cmdx/coercions/integer.rb +30 -24
- data/lib/cmdx/coercions/rational.rb +29 -24
- data/lib/cmdx/coercions/string.rb +19 -22
- data/lib/cmdx/coercions/symbol.rb +37 -0
- data/lib/cmdx/coercions/time.rb +26 -25
- data/lib/cmdx/configuration.rb +49 -108
- data/lib/cmdx/context.rb +222 -44
- data/lib/cmdx/deprecator.rb +61 -0
- data/lib/cmdx/errors.rb +42 -252
- data/lib/cmdx/exceptions.rb +39 -0
- data/lib/cmdx/faults.rb +78 -39
- data/lib/cmdx/freezer.rb +51 -0
- data/lib/cmdx/identifier.rb +30 -0
- data/lib/cmdx/locale.rb +52 -0
- data/lib/cmdx/log_formatters/json.rb +21 -22
- data/lib/cmdx/log_formatters/key_value.rb +20 -22
- data/lib/cmdx/log_formatters/line.rb +15 -22
- data/lib/cmdx/log_formatters/logstash.rb +22 -23
- data/lib/cmdx/log_formatters/raw.rb +16 -22
- data/lib/cmdx/middleware_registry.rb +70 -74
- data/lib/cmdx/middlewares/correlate.rb +90 -54
- data/lib/cmdx/middlewares/runtime.rb +58 -0
- data/lib/cmdx/middlewares/timeout.rb +48 -68
- data/lib/cmdx/railtie.rb +12 -45
- data/lib/cmdx/result.rb +229 -314
- data/lib/cmdx/task.rb +194 -366
- data/lib/cmdx/utils/call.rb +49 -0
- data/lib/cmdx/utils/condition.rb +71 -0
- data/lib/cmdx/utils/format.rb +61 -0
- data/lib/cmdx/validator_registry.rb +63 -72
- data/lib/cmdx/validators/exclusion.rb +38 -67
- data/lib/cmdx/validators/format.rb +48 -49
- data/lib/cmdx/validators/inclusion.rb +43 -74
- data/lib/cmdx/validators/length.rb +91 -154
- data/lib/cmdx/validators/numeric.rb +87 -162
- data/lib/cmdx/validators/presence.rb +37 -50
- data/lib/cmdx/version.rb +1 -1
- data/lib/cmdx/worker.rb +178 -0
- data/lib/cmdx/workflow.rb +85 -81
- data/lib/cmdx.rb +19 -13
- data/lib/generators/cmdx/install_generator.rb +14 -13
- data/lib/generators/cmdx/task_generator.rb +25 -50
- data/lib/generators/cmdx/templates/install.rb +11 -46
- data/lib/generators/cmdx/templates/task.rb.tt +3 -2
- data/lib/locales/en.yml +18 -4
- data/src/cmdx-logo.png +0 -0
- metadata +32 -116
- data/docs/ai_prompts.md +0 -393
- data/docs/basics/call.md +0 -317
- data/docs/configuration.md +0 -344
- data/docs/parameters/coercions.md +0 -396
- data/docs/parameters/defaults.md +0 -335
- data/docs/parameters/definitions.md +0 -446
- data/docs/parameters/namespacing.md +0 -378
- data/docs/parameters/validations.md +0 -405
- data/docs/testing.md +0 -553
- data/lib/cmdx/callback.rb +0 -53
- data/lib/cmdx/chain_inspector.rb +0 -56
- data/lib/cmdx/chain_serializer.rb +0 -63
- data/lib/cmdx/coercion.rb +0 -57
- data/lib/cmdx/coercions/virtual.rb +0 -29
- data/lib/cmdx/core_ext/hash.rb +0 -83
- data/lib/cmdx/core_ext/module.rb +0 -98
- data/lib/cmdx/core_ext/object.rb +0 -125
- data/lib/cmdx/correlator.rb +0 -122
- data/lib/cmdx/error.rb +0 -60
- data/lib/cmdx/fault.rb +0 -140
- data/lib/cmdx/immutator.rb +0 -52
- data/lib/cmdx/lazy_struct.rb +0 -246
- data/lib/cmdx/log_formatters/pretty_json.rb +0 -40
- data/lib/cmdx/log_formatters/pretty_key_value.rb +0 -38
- data/lib/cmdx/log_formatters/pretty_line.rb +0 -41
- data/lib/cmdx/logger.rb +0 -49
- data/lib/cmdx/logger_ansi.rb +0 -68
- data/lib/cmdx/logger_serializer.rb +0 -116
- data/lib/cmdx/middleware.rb +0 -70
- data/lib/cmdx/parameter.rb +0 -312
- data/lib/cmdx/parameter_evaluator.rb +0 -231
- data/lib/cmdx/parameter_inspector.rb +0 -66
- data/lib/cmdx/parameter_registry.rb +0 -106
- data/lib/cmdx/parameter_serializer.rb +0 -59
- data/lib/cmdx/result_ansi.rb +0 -71
- data/lib/cmdx/result_inspector.rb +0 -71
- data/lib/cmdx/result_logger.rb +0 -59
- data/lib/cmdx/result_serializer.rb +0 -104
- data/lib/cmdx/rspec/matchers.rb +0 -28
- data/lib/cmdx/rspec/result_matchers/be_executed.rb +0 -42
- data/lib/cmdx/rspec/result_matchers/be_failed_task.rb +0 -94
- data/lib/cmdx/rspec/result_matchers/be_skipped_task.rb +0 -94
- data/lib/cmdx/rspec/result_matchers/be_state_matchers.rb +0 -59
- data/lib/cmdx/rspec/result_matchers/be_status_matchers.rb +0 -57
- data/lib/cmdx/rspec/result_matchers/be_successful_task.rb +0 -87
- data/lib/cmdx/rspec/result_matchers/have_bad_outcome.rb +0 -51
- data/lib/cmdx/rspec/result_matchers/have_caused_failure.rb +0 -58
- data/lib/cmdx/rspec/result_matchers/have_chain_index.rb +0 -59
- data/lib/cmdx/rspec/result_matchers/have_context.rb +0 -86
- data/lib/cmdx/rspec/result_matchers/have_empty_metadata.rb +0 -54
- data/lib/cmdx/rspec/result_matchers/have_good_outcome.rb +0 -52
- data/lib/cmdx/rspec/result_matchers/have_metadata.rb +0 -114
- data/lib/cmdx/rspec/result_matchers/have_preserved_context.rb +0 -66
- data/lib/cmdx/rspec/result_matchers/have_received_thrown_failure.rb +0 -64
- data/lib/cmdx/rspec/result_matchers/have_runtime.rb +0 -78
- data/lib/cmdx/rspec/result_matchers/have_thrown_failure.rb +0 -76
- data/lib/cmdx/rspec/task_matchers/be_well_formed_task.rb +0 -62
- data/lib/cmdx/rspec/task_matchers/have_callback.rb +0 -85
- data/lib/cmdx/rspec/task_matchers/have_cmd_setting.rb +0 -68
- data/lib/cmdx/rspec/task_matchers/have_executed_callbacks.rb +0 -92
- data/lib/cmdx/rspec/task_matchers/have_middleware.rb +0 -46
- data/lib/cmdx/rspec/task_matchers/have_parameter.rb +0 -181
- data/lib/cmdx/task_deprecator.rb +0 -52
- data/lib/cmdx/task_processor.rb +0 -246
- data/lib/cmdx/task_serializer.rb +0 -57
- data/lib/cmdx/utils/ansi_color.rb +0 -73
- data/lib/cmdx/utils/log_timestamp.rb +0 -36
- data/lib/cmdx/utils/monotonic_runtime.rb +0 -34
- data/lib/cmdx/utils/name_affix.rb +0 -52
- data/lib/cmdx/validator.rb +0 -57
- data/lib/generators/cmdx/templates/workflow.rb.tt +0 -7
- data/lib/generators/cmdx/workflow_generator.rb +0 -84
- data/lib/locales/ar.yml +0 -35
- data/lib/locales/cs.yml +0 -35
- data/lib/locales/da.yml +0 -35
- data/lib/locales/de.yml +0 -35
- data/lib/locales/el.yml +0 -35
- data/lib/locales/es.yml +0 -35
- data/lib/locales/fi.yml +0 -35
- data/lib/locales/fr.yml +0 -35
- data/lib/locales/he.yml +0 -35
- data/lib/locales/hi.yml +0 -35
- data/lib/locales/it.yml +0 -35
- data/lib/locales/ja.yml +0 -35
- data/lib/locales/ko.yml +0 -35
- data/lib/locales/nl.yml +0 -35
- data/lib/locales/no.yml +0 -35
- data/lib/locales/pl.yml +0 -35
- data/lib/locales/pt.yml +0 -35
- data/lib/locales/ru.yml +0 -35
- data/lib/locales/sv.yml +0 -35
- data/lib/locales/th.yml +0 -35
- data/lib/locales/tr.yml +0 -35
- data/lib/locales/vi.yml +0 -35
- data/lib/locales/zh.yml +0 -35
@@ -2,107 +2,76 @@
|
|
2
2
|
|
3
3
|
module CMDx
|
4
4
|
module Validators
|
5
|
-
#
|
5
|
+
# Validates that a value is included in a specified set or range
|
6
6
|
#
|
7
|
-
# This validator ensures that
|
8
|
-
# of allowed values
|
9
|
-
#
|
10
|
-
|
7
|
+
# This validator ensures that the given value is present within a collection
|
8
|
+
# of allowed values or falls within a specified range. It supports both
|
9
|
+
# discrete value lists and range-based validations.
|
10
|
+
module Inclusion
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# @
|
17
|
-
# @
|
18
|
-
# @option options [Array, Range] :
|
19
|
-
# @option options [
|
20
|
-
# @option options [String] :
|
21
|
-
# @option options [String] :
|
22
|
-
# @option options [String] :
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# Validators::Inclusion.call("guest", inclusion: { in: ["user", "admin"] })
|
38
|
-
# # raises ValidationError: "must be one of: \"user\", \"admin\""
|
39
|
-
#
|
40
|
-
# @example Invalid inclusion from range
|
41
|
-
# Validators::Inclusion.call(15, inclusion: { in: 1..10 })
|
42
|
-
# # raises ValidationError: "must be within 1 and 10"
|
43
|
-
#
|
44
|
-
# @example Using a custom message
|
45
|
-
# Validators::Inclusion.call("guest", inclusion: { in: ["user", "admin"], message: "Invalid role selected" })
|
46
|
-
# # raises ValidationError: "Invalid role selected"
|
12
|
+
extend self
|
13
|
+
|
14
|
+
# Validates that a value is included in the specified options
|
15
|
+
#
|
16
|
+
# @param value [Object] The value to validate for inclusion
|
17
|
+
# @param options [Hash] Validation configuration options
|
18
|
+
# @option options [Array, Range] :in The collection of allowed values or range
|
19
|
+
# @option options [Array, Range] :within Alias for :in option
|
20
|
+
# @option options [String] :message Custom error message template
|
21
|
+
# @option options [String] :of_message Custom message for discrete value inclusions
|
22
|
+
# @option options [String] :in_message Custom message for range-based inclusions
|
23
|
+
# @option options [String] :within_message Custom message for range-based inclusions
|
24
|
+
#
|
25
|
+
# @return [nil] Returns nil if validation passes
|
26
|
+
#
|
27
|
+
# @raise [ValidationError] When the value is not found in the allowed collection
|
28
|
+
#
|
29
|
+
# @example Include specific values
|
30
|
+
# Inclusion.call("admin", in: ["admin", "user", "guest"])
|
31
|
+
# # => nil (validation passes)
|
32
|
+
# @example Include values within a range
|
33
|
+
# Inclusion.call(5, in: 1..10)
|
34
|
+
# # => nil (validation passes - 5 is within 1..10)
|
35
|
+
# @example Include with custom message
|
36
|
+
# Inclusion.call("test", in: ["admin", "user"], message: "must be one of: %{values}")
|
47
37
|
def call(value, options = {})
|
48
38
|
values = options[:in] || options[:within]
|
49
39
|
|
50
40
|
if values.is_a?(Range)
|
51
41
|
raise_within_validation_error!(values.begin, values.end, options) unless values.cover?(value)
|
52
|
-
elsif Array(values).none? { |v| v === value }
|
42
|
+
elsif Array(values).none? { |v| v === value }
|
53
43
|
raise_of_validation_error!(values, options)
|
54
44
|
end
|
55
45
|
end
|
56
46
|
|
57
47
|
private
|
58
48
|
|
59
|
-
# Raises
|
60
|
-
#
|
61
|
-
# @param values [Array] the allowed values
|
62
|
-
# @param options [Hash] validation options
|
49
|
+
# Raises validation error for discrete value inclusions
|
63
50
|
#
|
64
|
-
# @
|
51
|
+
# @param values [Array] The allowed values that caused the error
|
52
|
+
# @param options [Hash] Validation options containing custom messages
|
65
53
|
#
|
66
|
-
# @raise [ValidationError]
|
67
|
-
#
|
68
|
-
# @example
|
69
|
-
# raise_of_validation_error!(["user", "admin"], {})
|
70
|
-
# # raises ValidationError: "must be one of: \"user\", \"admin\""
|
54
|
+
# @raise [ValidationError] With appropriate error message
|
71
55
|
def raise_of_validation_error!(values, options)
|
72
|
-
values
|
56
|
+
values = values.map(&:inspect).join(", ") unless values.nil?
|
73
57
|
message = options[:of_message] || options[:message]
|
74
58
|
message %= { values: } unless message.nil?
|
75
59
|
|
76
|
-
raise ValidationError, message ||
|
77
|
-
"cmdx.validators.inclusion.of",
|
78
|
-
values:,
|
79
|
-
default: "must be one of: #{values}"
|
80
|
-
)
|
60
|
+
raise ValidationError, message || Locale.t("cmdx.validators.inclusion.of", values:)
|
81
61
|
end
|
82
62
|
|
83
|
-
# Raises
|
84
|
-
#
|
85
|
-
# @param min [Object] the minimum value of the range
|
86
|
-
# @param max [Object] the maximum value of the range
|
87
|
-
# @param options [Hash] validation options
|
88
|
-
#
|
89
|
-
# @return [void]
|
63
|
+
# Raises validation error for range-based inclusions
|
90
64
|
#
|
91
|
-
# @
|
65
|
+
# @param min [Object] The minimum value of the allowed range
|
66
|
+
# @param max [Object] The maximum value of the allowed range
|
67
|
+
# @param options [Hash] Validation options containing custom messages
|
92
68
|
#
|
93
|
-
# @
|
94
|
-
# raise_within_validation_error!(1, 10, {})
|
95
|
-
# # raises ValidationError: "must be within 1 and 10"
|
69
|
+
# @raise [ValidationError] With appropriate error message
|
96
70
|
def raise_within_validation_error!(min, max, options)
|
97
71
|
message = options[:in_message] || options[:within_message] || options[:message]
|
98
72
|
message %= { min:, max: } unless message.nil?
|
99
73
|
|
100
|
-
raise ValidationError, message ||
|
101
|
-
"cmdx.validators.inclusion.within",
|
102
|
-
min:,
|
103
|
-
max:,
|
104
|
-
default: "must be within #{min} and #{max}"
|
105
|
-
)
|
74
|
+
raise ValidationError, message || Locale.t("cmdx.validators.inclusion.within", min:, max:)
|
106
75
|
end
|
107
76
|
|
108
77
|
end
|
@@ -2,223 +2,160 @@
|
|
2
2
|
|
3
3
|
module CMDx
|
4
4
|
module Validators
|
5
|
-
#
|
5
|
+
# Validates the length of a value against various constraints.
|
6
6
|
#
|
7
|
-
# This validator
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# @
|
18
|
-
# @
|
19
|
-
# @option options [Range] :length
|
20
|
-
# @option options [Range] :length
|
21
|
-
# @option options [
|
22
|
-
# @option options [
|
23
|
-
# @option options [Integer] :
|
24
|
-
# @option options [Integer] :
|
25
|
-
# @option options [
|
26
|
-
# @option options [
|
27
|
-
# @option options [String] :
|
28
|
-
# @option options [String] :
|
29
|
-
# @option options [String] :
|
30
|
-
# @option options [String] :
|
31
|
-
# @option options [String] :
|
32
|
-
# @option options [String] :
|
33
|
-
# @option options [String] :
|
34
|
-
#
|
35
|
-
# @
|
36
|
-
#
|
37
|
-
# @
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# @
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# @example
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# # raises ValidationError: "cannot be empty"
|
7
|
+
# This validator supports multiple length validation strategies including exact length,
|
8
|
+
# minimum/maximum bounds, and range-based validation. It can be used to ensure
|
9
|
+
# values meet specific length requirements for strings, arrays, and other
|
10
|
+
# enumerable objects.
|
11
|
+
module Length
|
12
|
+
|
13
|
+
extend self
|
14
|
+
|
15
|
+
# Validates a value's length against specified constraints.
|
16
|
+
#
|
17
|
+
# @param value [String, Array, Hash, Object] The value to validate (must respond to #length)
|
18
|
+
# @param options [Hash] Validation options
|
19
|
+
# @option options [Range] :within Range that the length must fall within (inclusive)
|
20
|
+
# @option options [Range] :not_within Range that the length must not fall within
|
21
|
+
# @option options [Range] :in Alias for :within
|
22
|
+
# @option options [Range] :not_in Range that the length must not fall within
|
23
|
+
# @option options [Integer] :min Minimum allowed length
|
24
|
+
# @option options [Integer] :max Maximum allowed length
|
25
|
+
# @option options [Integer] :is Exact required length
|
26
|
+
# @option options [Integer] :is_not Length that is not allowed
|
27
|
+
# @option options [String] :message Custom error message for all validations
|
28
|
+
# @option options [String] :within_message Custom message for within/range validations
|
29
|
+
# @option options [String] :in_message Custom message for :in validation
|
30
|
+
# @option options [String] :not_within_message Custom message for not_within validation
|
31
|
+
# @option options [String] :not_in_message Custom message for not_in validation
|
32
|
+
# @option options [String] :min_message Custom message for minimum length validation
|
33
|
+
# @option options [String] :max_message Custom message for maximum length validation
|
34
|
+
# @option options [String] :is_message Custom message for exact length validation
|
35
|
+
# @option options [String] :is_not_message Custom message for is_not validation
|
36
|
+
#
|
37
|
+
# @return [nil] Returns nil if validation passes
|
38
|
+
#
|
39
|
+
# @raise [ValidationError] When validation fails
|
40
|
+
# @raise [ArgumentError] When unknown validation options are provided
|
41
|
+
#
|
42
|
+
# @example Exact length validation
|
43
|
+
# Length.call("hello", is: 5)
|
44
|
+
# # => nil (validation passes)
|
45
|
+
# @example Range-based validation
|
46
|
+
# Length.call("test", within: 3..6)
|
47
|
+
# # => nil (validation passes - length 4 is within range)
|
48
|
+
# @example Min/max validation
|
49
|
+
# Length.call("username", min: 3, max: 20)
|
50
|
+
# # => nil (validation passes - length 8 is between 3 and 20)
|
51
|
+
# @example Exclusion validation
|
52
|
+
# Length.call("short", not_in: 1..3)
|
53
|
+
# # => nil (validation passes - length 5 is not in excluded range)
|
55
54
|
def call(value, options = {})
|
56
55
|
case options
|
57
|
-
in
|
56
|
+
in within:
|
58
57
|
raise_within_validation_error!(within.begin, within.end, options) unless within.cover?(value.length)
|
59
|
-
in
|
58
|
+
in not_within:
|
60
59
|
raise_not_within_validation_error!(not_within.begin, not_within.end, options) if not_within.cover?(value.length)
|
61
|
-
in
|
62
|
-
raise_within_validation_error!(
|
63
|
-
in
|
60
|
+
in in: xin
|
61
|
+
raise_within_validation_error!(xin.begin, xin.end, options) unless xin.cover?(value.length)
|
62
|
+
in not_in:
|
64
63
|
raise_not_within_validation_error!(not_in.begin, not_in.end, options) if not_in.cover?(value.length)
|
65
|
-
in
|
64
|
+
in min:, max:
|
66
65
|
raise_within_validation_error!(min, max, options) unless value.length.between?(min, max)
|
67
|
-
in
|
66
|
+
in min:
|
68
67
|
raise_min_validation_error!(min, options) unless min <= value.length
|
69
|
-
in
|
68
|
+
in max:
|
70
69
|
raise_max_validation_error!(max, options) unless value.length <= max
|
71
|
-
in
|
70
|
+
in is:
|
72
71
|
raise_is_validation_error!(is, options) unless value.length == is
|
73
|
-
in
|
72
|
+
in is_not:
|
74
73
|
raise_is_not_validation_error!(is_not, options) if value.length == is_not
|
75
74
|
else
|
76
|
-
raise ArgumentError, "
|
75
|
+
raise ArgumentError, "unknown length validator options given"
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
79
|
private
|
81
80
|
|
82
|
-
# Raises
|
81
|
+
# Raises validation error for within/range validations.
|
83
82
|
#
|
84
|
-
# @param min [Integer]
|
85
|
-
# @param max [Integer]
|
86
|
-
# @param options [Hash]
|
83
|
+
# @param min [Integer] Minimum length value
|
84
|
+
# @param max [Integer] Maximum length value
|
85
|
+
# @param options [Hash] Validation options containing custom messages
|
87
86
|
#
|
88
|
-
# @
|
89
|
-
#
|
90
|
-
# @raise [ValidationError] always raised with appropriate message
|
91
|
-
#
|
92
|
-
# @example
|
93
|
-
# raise_within_validation_error!(5, 10, {})
|
94
|
-
# # raises ValidationError: "length must be within 5 and 10"
|
87
|
+
# @raise [ValidationError] Always raised with appropriate message
|
95
88
|
def raise_within_validation_error!(min, max, options)
|
96
89
|
message = options[:within_message] || options[:in_message] || options[:message]
|
97
90
|
message %= { min:, max: } unless message.nil?
|
98
91
|
|
99
|
-
raise ValidationError, message ||
|
100
|
-
"cmdx.validators.length.within",
|
101
|
-
min:,
|
102
|
-
max:,
|
103
|
-
default: "length must be within #{min} and #{max}"
|
104
|
-
)
|
92
|
+
raise ValidationError, message || Locale.t("cmdx.validators.length.within", min:, max:)
|
105
93
|
end
|
106
94
|
|
107
|
-
# Raises
|
108
|
-
#
|
109
|
-
# @param min [Integer] the minimum forbidden length
|
110
|
-
# @param max [Integer] the maximum forbidden length
|
111
|
-
# @param options [Hash] validation options
|
95
|
+
# Raises validation error for not_within validations.
|
112
96
|
#
|
113
|
-
# @
|
97
|
+
# @param min [Integer] Minimum length value
|
98
|
+
# @param max [Integer] Maximum length value
|
99
|
+
# @param options [Hash] Validation options containing custom messages
|
114
100
|
#
|
115
|
-
# @raise [ValidationError]
|
116
|
-
#
|
117
|
-
# @example
|
118
|
-
# raise_not_within_validation_error!(5, 10, {})
|
119
|
-
# # raises ValidationError: "length must not be within 5 and 10"
|
101
|
+
# @raise [ValidationError] Always raised with appropriate message
|
120
102
|
def raise_not_within_validation_error!(min, max, options)
|
121
103
|
message = options[:not_within_message] || options[:not_in_message] || options[:message]
|
122
104
|
message %= { min:, max: } unless message.nil?
|
123
105
|
|
124
|
-
raise ValidationError, message ||
|
125
|
-
"cmdx.validators.length.not_within",
|
126
|
-
min:,
|
127
|
-
max:,
|
128
|
-
default: "length must not be within #{min} and #{max}"
|
129
|
-
)
|
106
|
+
raise ValidationError, message || Locale.t("cmdx.validators.length.not_within", min:, max:)
|
130
107
|
end
|
131
108
|
|
132
|
-
# Raises
|
133
|
-
#
|
134
|
-
# @param min [Integer] the minimum acceptable length
|
135
|
-
# @param options [Hash] validation options
|
136
|
-
#
|
137
|
-
# @return [void]
|
109
|
+
# Raises validation error for minimum length validation.
|
138
110
|
#
|
139
|
-
# @
|
111
|
+
# @param min [Integer] Minimum required length
|
112
|
+
# @param options [Hash] Validation options containing custom messages
|
140
113
|
#
|
141
|
-
# @
|
142
|
-
# raise_min_validation_error!(5, {})
|
143
|
-
# # raises ValidationError: "length must be at least 5"
|
114
|
+
# @raise [ValidationError] Always raised with appropriate message
|
144
115
|
def raise_min_validation_error!(min, options)
|
145
116
|
message = options[:min_message] || options[:message]
|
146
117
|
message %= { min: } unless message.nil?
|
147
118
|
|
148
|
-
raise ValidationError, message ||
|
149
|
-
"cmdx.validators.length.min",
|
150
|
-
min:,
|
151
|
-
default: "length must be at least #{min}"
|
152
|
-
)
|
119
|
+
raise ValidationError, message || Locale.t("cmdx.validators.length.min", min:)
|
153
120
|
end
|
154
121
|
|
155
|
-
# Raises
|
122
|
+
# Raises validation error for maximum length validation.
|
156
123
|
#
|
157
|
-
# @param max [Integer]
|
158
|
-
# @param options [Hash]
|
124
|
+
# @param max [Integer] Maximum allowed length
|
125
|
+
# @param options [Hash] Validation options containing custom messages
|
159
126
|
#
|
160
|
-
# @
|
161
|
-
#
|
162
|
-
# @raise [ValidationError] always raised with appropriate message
|
163
|
-
#
|
164
|
-
# @example
|
165
|
-
# raise_max_validation_error!(10, {})
|
166
|
-
# # raises ValidationError: "length must be at most 10"
|
127
|
+
# @raise [ValidationError] Always raised with appropriate message
|
167
128
|
def raise_max_validation_error!(max, options)
|
168
129
|
message = options[:max_message] || options[:message]
|
169
130
|
message %= { max: } unless message.nil?
|
170
131
|
|
171
|
-
raise ValidationError, message ||
|
172
|
-
"cmdx.validators.length.max",
|
173
|
-
max:,
|
174
|
-
default: "length must be at most #{max}"
|
175
|
-
)
|
132
|
+
raise ValidationError, message || Locale.t("cmdx.validators.length.max", max:)
|
176
133
|
end
|
177
134
|
|
178
|
-
# Raises
|
179
|
-
#
|
180
|
-
# @param is [Integer] the exact required length
|
181
|
-
# @param options [Hash] validation options
|
135
|
+
# Raises validation error for exact length validation.
|
182
136
|
#
|
183
|
-
# @
|
137
|
+
# @param is [Integer] Required exact length
|
138
|
+
# @param options [Hash] Validation options containing custom messages
|
184
139
|
#
|
185
|
-
# @raise [ValidationError]
|
186
|
-
#
|
187
|
-
# @example
|
188
|
-
# raise_is_validation_error!(5, {})
|
189
|
-
# # raises ValidationError: "length must be 5"
|
140
|
+
# @raise [ValidationError] Always raised with appropriate message
|
190
141
|
def raise_is_validation_error!(is, options)
|
191
142
|
message = options[:is_message] || options[:message]
|
192
143
|
message %= { is: } unless message.nil?
|
193
144
|
|
194
|
-
raise ValidationError, message ||
|
195
|
-
"cmdx.validators.length.is",
|
196
|
-
is:,
|
197
|
-
default: "length must be #{is}"
|
198
|
-
)
|
145
|
+
raise ValidationError, message || Locale.t("cmdx.validators.length.is", is:)
|
199
146
|
end
|
200
147
|
|
201
|
-
# Raises
|
202
|
-
#
|
203
|
-
# @param is_not [Integer] the exact forbidden length
|
204
|
-
# @param options [Hash] validation options
|
205
|
-
#
|
206
|
-
# @return [void]
|
148
|
+
# Raises validation error for is_not length validation.
|
207
149
|
#
|
208
|
-
# @
|
150
|
+
# @param is_not [Integer] Length that is not allowed
|
151
|
+
# @param options [Hash] Validation options containing custom messages
|
209
152
|
#
|
210
|
-
# @
|
211
|
-
# raise_is_not_validation_error!(5, {})
|
212
|
-
# # raises ValidationError: "length must not be 5"
|
153
|
+
# @raise [ValidationError] Always raised with appropriate message
|
213
154
|
def raise_is_not_validation_error!(is_not, options)
|
214
155
|
message = options[:is_not_message] || options[:message]
|
215
156
|
message %= { is_not: } unless message.nil?
|
216
157
|
|
217
|
-
raise ValidationError, message ||
|
218
|
-
"cmdx.validators.length.is_not",
|
219
|
-
is_not:,
|
220
|
-
default: "length must not be #{is_not}"
|
221
|
-
)
|
158
|
+
raise ValidationError, message || Locale.t("cmdx.validators.length.is_not", is_not:)
|
222
159
|
end
|
223
160
|
|
224
161
|
end
|