Sha256: bd007549fff5da473f67e5fbfdc8700ea0f714f1f3de40e56b4395c0a7a02914

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Granite
  module Form
    module Model
      module Associations
        module Validations
          def valid_ancestry?
            errors.clear
            validate_nested!
            run_validations!
          end

          alias validate_ancestry valid_ancestry?

          def invalid_ancestry?
            !valid_ancestry?
          end

          def validate_ancestry!
            valid_ancestry? || raise_validation_error
          end

          private

          def validate_nested!
            association_names.each do |name|
              association = association(name)
              invalid_block = if association.reflection.klass.method_defined?(:invalid_ansestry?)
                                ->(object) { object.invalid_ansestry? }
                              else
                                ->(object) { object.invalid? }
                              end

              Granite::Form::Model::Validations::NestedValidator
                .validate_nested(self, name, association.target, &invalid_block)
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
granite-form-0.6.0 lib/granite/form/model/associations/validations.rb