Skip to content

Commit

Permalink
[FIX] attribute validation fix (#3)
Browse files Browse the repository at this point in the history
* attribute validation fix

* fix condition
  • Loading branch information
phenchaw authored Mar 23, 2022
1 parent d516f22 commit 4f3bf31
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/ph_model/concerns/attribute_nested_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def format_nested_attribute_name(attribute_name, index, item_value)
end

def check_one(value, attribute_name)
return if !value.respond_to?(:valid?) || !value.respond_to?(:errors) || value.errors.nil? || value.valid?
return if !value.respond_to?(:valid?) || !value.respond_to?(:errors) || value.errors.nil? ||
(value.respond_to?(:frozen?) && value.frozen?) || value.valid?
value.errors.full_messages.each do |message|
errors.add(:base, "#{attribute_name}.#{message}")
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ph_model/concerns/attribute_type_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def type_match?(attribute_name)
when nil
true
when Array
if type.count != 1
raise ArgumentError, "don't know how to handle type: #{type.inspect}"
if type.count > 1
type.any? { |typ| value.is_a?(typ) }
else
if value.kind_of? Array
value.all? { |item| item.is_a?(type.first) }
Expand Down
2 changes: 1 addition & 1 deletion lib/ph_model/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module PhModel
VERSION = '1.1.2'.freeze
VERSION = '1.1.3'.freeze
end

0 comments on commit 4f3bf31

Please sign in to comment.