Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .cursor/rules/cursor-instructions.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -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

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
cmdx (1.5.0)
cmdx (1.5.1)
bigdecimal
logger
zeitwerk
Expand Down
2 changes: 1 addition & 1 deletion lib/cmdx/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion lib/cmdx/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions lib/cmdx/validators/length.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 !length.nil? && (min <= length)
in max:
raise_max_validation_error!(max, options) unless value.length <= max
raise_max_validation_error!(max, options) unless !length.nil? && (length <= max)
in is:
raise_is_validation_error!(is, options) unless value.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 value.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
Expand Down
18 changes: 9 additions & 9 deletions lib/cmdx/validators/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ 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
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
Expand Down
2 changes: 1 addition & 1 deletion lib/cmdx/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module CMDx

VERSION = "1.5.0"
VERSION = "1.5.1"

end