Sha256: 8d4648dc442cb11ca9475489c86d5c7ce66976cfb482086a348ac4130656bd74
Contents?: true
Size: 759 Bytes
Versions: 1
Compression:
Stored size: 759 Bytes
Contents
module FieldsValidator extend ActiveSupport::Concern included do validate :validate_column_names if respond_to?(:validate) end class_methods do def validate_required_attributes required_attributes.each do |a| validates a.to_sym, presence: true end if required_attributes.any? end def required_attributes defined?(super) and super.is_a?(Array) ? super : [] end def required_database_fields defined?(super) and super.is_a?(Array) ? super : [] end end private def validate_column_names required_database_fields.each { |rdf| errors_add(rdf, "does not have a column in the database.") unless self.class.column_names.include?(rdf)} if required_database_fields.any? end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
morse_fields_validator-1.1.1 | lib/morse_fields_validator/fields_validator.rb |