Module: ActiveModel::Validations::ClassMethods

Defined in:
lib/validates_subset.rb

Instance Method Summary collapse

Instance Method Details

#validates_subset(attribute_name, superset, options = {}) ⇒ Object

Validates that an attribute is a subset of an expected set:

class Foo

include ActiveModel::Validations

attr_accessor :thing, :something

validates_subset :thing, ['something', 'another thing', 'a third thing']
validates_subset :something, [:foo, :bar]

end



105
106
107
108
# File 'lib/validates_subset.rb', line 105

def validates_subset(attribute_name, superset, options = {})
  args = ValidatesSubset::Arguments.new(attribute_name, superset, options)
  validates_with SubsetValidator, _merge_attributes(args.to_validation_attributes)
end