Class: VolumeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/volume_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'app/validators/volume_validator.rb', line 2

def validate_each(record, attribute, value)
  if value[:volumes_attributes].present?
    value[:volumes_attributes].each do |_, attrs|
      if attrs.key?("capacity") && attrs.key?("storage_class")
        if attrs["capacity"].to_s.empty? || /\A\d+G?\Z/.match(attrs["capacity"].to_s).nil?
          record.errors.add(attribute, _("Volume size %s is not valid") % attrs['capacity'])
        end
      end
    end
  end
end