Module: CouchSurfer::Validations::InstanceMethods
- Defined in:
- lib/couch_surfer/validations.rb
Instance Method Summary collapse
Instance Method Details
#is_unique?(field, options) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/couch_surfer/validations.rb', line 18 def is_unique?(field, ) if [:view] view_name = [:view] query = [:query].is_a?(Proc) ? self.instance_eval(&[:query]) : nil end view_name ||= "by_#{field}" query ||= {:key => self.send(field)} result = self.class.send(view_name, query) if result.blank? return true else return !id.blank? && (id == result.first.id) end end |
#validate_instance ⇒ Object
33 34 35 |
# File 'lib/couch_surfer/validations.rb', line 33 def validate_instance throw(:halt, false) unless valid? end |