Module: Ohm::Model::Validations
- Includes:
- Validations
- Included in:
- Ohm::Model
- Defined in:
- lib/ohm.rb
Overview
All validations which need to access the Redis database goes here. As of this writing, #assert_unique is the only assertion contained within this module.
Instance Method Summary (collapse)
-
- (Object) assert_unique(atts, error = [atts, :not_unique])
Validates that the attribute or array of attributes are unique.
Methods included from Validations
#assert, #assert_format, #assert_numeric, #assert_present, #errors, #valid?, #validate
Instance Method Details
- (Object) assert_unique(:name) - (Object) assert_unique([:street, :city])
Validates that the attribute or array of attributes are unique. For this, an index of the same kind must exist.
948 949 950 951 952 953 |
# File 'lib/ohm.rb', line 948 def assert_unique(atts, error = [atts, :not_unique]) indices = Array(atts).map { |att| index_key_for(att, send(att)) } result = db.sinter(*indices) assert result.empty? || !new? && result.include?(id.to_s), error end |