Module: PhModel::Concerns::AttributeNestedValidation
- Extended by:
- ActiveSupport::Concern
- Included in:
- PhModel
- Defined in:
- lib/ph_model/concerns/attribute_nested_validation.rb
Instance Method Summary collapse
- #check_one(value, attribute_name) ⇒ Object
- #format_nested_attribute_name(attribute_name, index, item_value) ⇒ Object
- #validate_nested_attributes ⇒ Object
Instance Method Details
#check_one(value, attribute_name) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ph_model/concerns/attribute_nested_validation.rb', line 29 def check_one(value, attribute_name) return if !value.respond_to?(:valid?) || !value.respond_to?(:errors) || value.errors.nil? || value.valid? value.errors..each do || errors.add(:base, "#{attribute_name}.#{}") end end |
#format_nested_attribute_name(attribute_name, index, item_value) ⇒ Object
25 26 27 |
# File 'lib/ph_model/concerns/attribute_nested_validation.rb', line 25 def format_nested_attribute_name(attribute_name, index, item_value) "#{attribute_name}[#{index}]" end |
#validate_nested_attributes ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ph_model/concerns/attribute_nested_validation.rb', line 10 def validate_nested_attributes self.class.attributes.each do |attribute_name, info| value = send(attribute_name) if info[:type].is_a? Array if value.respond_to? :each_with_index value.each_with_index do |item_value, index| check_one(item_value, format_nested_attribute_name(attribute_name, index, item_value)) end end else check_one(value, attribute_name) end end end |