module Spira::Validations::ClassMethods
Public Instance Methods
create!(properties = {}, options = {}) { |object| ... }
click to toggle source
Creates an object just like Base.create but calls save!
instead of save
so an exception is raised if the record is invalid.
# File lib/spira/validations.rb, line 30 def create!(properties = {}, options = {}, &block) if properties.is_a?(Array) properties.collect { |attr| create!(attr, options, &block) } else object = new(properties, options) yield(object) if block_given? object.save! object end end
validates_uniqueness_of(*attr_names)
click to toggle source
Validates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user can be named “davidhh”.
class Person < Spira::Base validates_uniqueness_of :user_name end
# File lib/spira/validations/uniqueness.rb, line 38 def validates_uniqueness_of(*attr_names) validates_with UniquenessValidator, _merge_attributes(attr_names) end