Sha256: d67a2c9e936e6fd97b5ba279940041c0185a38f4cd7adb69cc873acb6c5afd4f

Contents?: true

Size: 460 Bytes

Versions: 8

Compression:

Stored size: 460 Bytes

Contents

module PhModel
  module Concerns
    module AttributeRequiredValidation
      extend ActiveSupport::Concern

      included do |other|
        other.validate :validate_required_attributes
      end

      def validate_required_attributes
        self.class.attributes.each do |attribute_name, info|
          if info[:required] && send(attribute_name).blank?
            errors.add(attribute_name, :empty)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ph_model-1.2.0 lib/ph_model/concerns/attribute_required_validation.rb
ph_model-1.1.3 lib/ph_model/concerns/attribute_required_validation.rb
ph_model-1.1.2 lib/ph_model/concerns/attribute_required_validation.rb
ph_model-1.1.1 lib/ph_model/concerns/attribute_required_validation.rb
ph_model-1.1.0 lib/ph_model/concerns/attribute_required_validation.rb
ph_model-1.0.2 lib/ph_model/concerns/attribute_required_validation.rb
ph_model-1.0.1 lib/ph_model/concerns/attribute_required_validation.rb
ph_model-1.0.0 lib/ph_model/concerns/attribute_required_validation.rb