From d6172e994c0a1fc830df2b487bb7e2836aca1867 Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Thu, 21 Aug 2025 23:09:30 -0400 Subject: [PATCH 1/7] Namespace i18n module --- lib/cmdx/locale.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cmdx/locale.rb b/lib/cmdx/locale.rb index 03312fce9..816c55c99 100644 --- a/lib/cmdx/locale.rb +++ b/lib/cmdx/locale.rb @@ -36,7 +36,7 @@ module Locale # # => "Custom fallback message" def translate(key, **options) options[:default] ||= EN.dig("en", *key.to_s.split(".")) - return I18n.t(key, **options) if defined?(I18n) + return ::I18n.t(key, **options) if defined?(::I18n) case message = options.delete(:default) when NilClass then "Translation missing: #{key}" From 8303ef425b453513bd805d70d6884f48677cb0af Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Thu, 21 Aug 2025 23:10:02 -0400 Subject: [PATCH 2/7] Safe navigate length validator --- lib/cmdx/validators/length.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/cmdx/validators/length.rb b/lib/cmdx/validators/length.rb index 2e5d30612..1fa915c44 100644 --- a/lib/cmdx/validators/length.rb +++ b/lib/cmdx/validators/length.rb @@ -52,25 +52,27 @@ module Length # Length.call("short", not_in: 1..3) # # => nil (validation passes - length 5 is not in excluded range) def call(value, options = {}) + length = value&.length + case options in within: - raise_within_validation_error!(within.begin, within.end, options) unless within.cover?(value.length) + raise_within_validation_error!(within.begin, within.end, options) unless within&.cover?(length) in not_within: - raise_not_within_validation_error!(not_within.begin, not_within.end, options) if not_within.cover?(value.length) + raise_not_within_validation_error!(not_within.begin, not_within.end, options) if not_within&.cover?(length) in in: xin - raise_within_validation_error!(xin.begin, xin.end, options) unless xin.cover?(value.length) + raise_within_validation_error!(xin.begin, xin.end, options) unless xin&.cover?(length) in not_in: - raise_not_within_validation_error!(not_in.begin, not_in.end, options) if not_in.cover?(value.length) + raise_not_within_validation_error!(not_in.begin, not_in.end, options) if not_in&.cover?(length) in min:, max: - raise_within_validation_error!(min, max, options) unless value.length.between?(min, max) + raise_within_validation_error!(min, max, options) unless length&.between?(min, max) in min: - raise_min_validation_error!(min, options) unless min <= value.length + raise_min_validation_error!(min, options) unless min <= length in max: - raise_max_validation_error!(max, options) unless value.length <= max + raise_max_validation_error!(max, options) unless length <= max in is: - raise_is_validation_error!(is, options) unless value.length == is + raise_is_validation_error!(is, options) unless length == is in is_not: - raise_is_not_validation_error!(is_not, options) if value.length == is_not + raise_is_not_validation_error!(is_not, options) if length == is_not else raise ArgumentError, "unknown length validator options given" end From dd2407ba332ab4ee47102a36be5ef160cf71a34b Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Thu, 21 Aug 2025 23:10:14 -0400 Subject: [PATCH 3/7] Safe navigate numeric validator --- lib/cmdx/validators/numeric.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/cmdx/validators/numeric.rb b/lib/cmdx/validators/numeric.rb index d897e1e27..fbd483b50 100644 --- a/lib/cmdx/validators/numeric.rb +++ b/lib/cmdx/validators/numeric.rb @@ -51,15 +51,15 @@ module Numeric def call(value, options = {}) case options in within: - raise_within_validation_error!(within.begin, within.end, options) unless within.cover?(value) + raise_within_validation_error!(within.begin, within.end, options) unless within&.cover?(value) in not_within: - raise_not_within_validation_error!(not_within.begin, not_within.end, options) if not_within.cover?(value) + raise_not_within_validation_error!(not_within.begin, not_within.end, options) if not_within&.cover?(value) in in: xin - raise_within_validation_error!(xin.begin, xin.end, options) unless xin.cover?(value) + raise_within_validation_error!(xin.begin, xin.end, options) unless xin&.cover?(value) in not_in: - raise_not_within_validation_error!(not_in.begin, not_in.end, options) if not_in.cover?(value) + raise_not_within_validation_error!(not_in.begin, not_in.end, options) if not_in&.cover?(value) in min:, max: - raise_within_validation_error!(min, max, options) unless value.between?(min, max) + raise_within_validation_error!(min, max, options) unless value&.between?(min, max) in min: raise_min_validation_error!(min, options) unless min <= value in max: From 28840a62339e2e571bf5a23fc59e079b0530ac57 Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Thu, 21 Aug 2025 23:10:25 -0400 Subject: [PATCH 4/7] Update cursor-instructions.mdc --- .cursor/rules/cursor-instructions.mdc | 1 - 1 file changed, 1 deletion(-) diff --git a/.cursor/rules/cursor-instructions.mdc b/.cursor/rules/cursor-instructions.mdc index 751b89683..07e045dd8 100644 --- a/.cursor/rules/cursor-instructions.mdc +++ b/.cursor/rules/cursor-instructions.mdc @@ -58,4 +58,3 @@ business logic within service/command objects. - Keep comments up-to-date with code changes - Keep documentation consistent - Update CHANGELOG.md with any changes - From 2968579527aa2ad92588cf98d1fa414838077498 Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Thu, 21 Aug 2025 23:15:44 -0400 Subject: [PATCH 5/7] nil check length and numeric validators --- lib/cmdx/validators/length.rb | 8 ++++---- lib/cmdx/validators/numeric.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/cmdx/validators/length.rb b/lib/cmdx/validators/length.rb index 1fa915c44..d290b2efc 100644 --- a/lib/cmdx/validators/length.rb +++ b/lib/cmdx/validators/length.rb @@ -66,13 +66,13 @@ def call(value, options = {}) in min:, max: raise_within_validation_error!(min, max, options) unless length&.between?(min, max) in min: - raise_min_validation_error!(min, options) unless min <= length + raise_min_validation_error!(min, options) unless !length.nil? && (min <= length) in max: - raise_max_validation_error!(max, options) unless length <= max + raise_max_validation_error!(max, options) unless !length.nil? && (length <= max) in is: - raise_is_validation_error!(is, options) unless length == is + raise_is_validation_error!(is, options) unless !length.nil? && (length == is) in is_not: - raise_is_not_validation_error!(is_not, options) if length == is_not + raise_is_not_validation_error!(is_not, options) if !length.nil? && (length == is_not) else raise ArgumentError, "unknown length validator options given" end diff --git a/lib/cmdx/validators/numeric.rb b/lib/cmdx/validators/numeric.rb index fbd483b50..16137020c 100644 --- a/lib/cmdx/validators/numeric.rb +++ b/lib/cmdx/validators/numeric.rb @@ -61,13 +61,13 @@ def call(value, options = {}) in min:, max: raise_within_validation_error!(min, max, options) unless value&.between?(min, max) in min: - raise_min_validation_error!(min, options) unless min <= value + raise_min_validation_error!(min, options) unless !value.nil? && (min <= value) in max: - raise_max_validation_error!(max, options) unless value <= max + raise_max_validation_error!(max, options) unless !value.nil? && (value <= max) in is: - raise_is_validation_error!(is, options) unless value == is + raise_is_validation_error!(is, options) unless !value.nil? && (value == is) in is_not: - raise_is_not_validation_error!(is_not, options) if value == is_not + raise_is_not_validation_error!(is_not, options) if !value.nil? && (value == is_not) else raise ArgumentError, "unknown numeric validator options given" end From 97b2775e8ef36f5458bd4ab165242838430c3e22 Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Thu, 21 Aug 2025 23:28:48 -0400 Subject: [PATCH 6/7] Fix railtie directory path --- lib/cmdx/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cmdx/railtie.rb b/lib/cmdx/railtie.rb index ec46acb48..8ed9a4ece 100644 --- a/lib/cmdx/railtie.rb +++ b/lib/cmdx/railtie.rb @@ -23,7 +23,7 @@ class Railtie < Rails::Railtie # # in the CMDx gem's locales directory initializer("cmdx.configure_locales") do |app| Array(app.config.i18n.available_locales).each do |locale| - path = CMDx.gem_path.join("locales/#{locale}.yml") + path = CMDx.gem_path.join("lib/locales/#{locale}.yml") next unless File.file?(path) I18n.load_path << path From 97f3b34ae2e16ae07109dcdbd72e3cf66375eef3 Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Thu, 21 Aug 2025 23:35:03 -0400 Subject: [PATCH 7/7] Add changelog --- CHANGELOG.md | 7 +++++++ Gemfile.lock | 2 +- lib/cmdx/version.rb | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f62dc1cf..3fd5a29f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [TODO] +## [1.5.1] - 2025-08-21 + +### Changes +- Prefix I18n with `::` to play nice with `CMDx::I18n` +- Safe navigate length and numeric validators +- Update railtie file path points to correct directory + ## [1.5.0] - 2025-08-21 ### Changes diff --git a/Gemfile.lock b/Gemfile.lock index 2b320fda7..0d91b3dbf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - cmdx (1.5.0) + cmdx (1.5.1) bigdecimal logger zeitwerk diff --git a/lib/cmdx/version.rb b/lib/cmdx/version.rb index 685862411..db85b1650 100644 --- a/lib/cmdx/version.rb +++ b/lib/cmdx/version.rb @@ -2,6 +2,6 @@ module CMDx - VERSION = "1.5.0" + VERSION = "1.5.1" end