Skip to content

Commit

Permalink
Moved validations to validate method
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed May 5, 2024
1 parent 81722af commit 3866f74
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/neighbor/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ def self.neighbor_attributes

return if @neighbor_attributes.size != attribute_names.size

before_save do
validate do
self.class.neighbor_attributes.each do |k, v|
value = read_attribute(k)
next if value.nil?
Neighbor::Utils.validate(value, dimensions: v[:dimensions], column_info: self.class.columns_hash[k.to_s])
end
end

column_info = self.class.columns_hash[k.to_s]
Neighbor::Utils.validate(value, dimensions: v[:dimensions], column_info: column_info)
self[k] = Neighbor::Utils.normalize(value, column_info: column_info) if v[:normalize]
# TODO move to normalizes when Rails 7.0 no longer supported
before_save do
self.class.neighbor_attributes.each do |k, v|
next unless v[:normalize]
value = read_attribute(k)
next if value.nil?
self[k] = Neighbor::Utils.normalize(value, column_info: self.class.columns_hash[k.to_s])
end
end

Expand Down

0 comments on commit 3866f74

Please sign in to comment.