Module: Devise::Orm::CouchPotato::ClassMethods

Defined in:
lib/devise/orm/couch_potato.rb

Instance Method Summary collapse

Instance Method Details

#devise_modules_hook!Object



24
25
26
27
28
29
# File 'lib/devise/orm/couch_potato.rb', line 24

def devise_modules_hook!
  create_authentication_views
  yield
  return unless Devise.apply_schema
  devise_modules.each { |m| send(m) if respond_to?(m, true) }
end

#validates_uniqueness_of(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/devise/orm/couch_potato.rb', line 7

def validates_uniqueness_of(*args)
  options = args.extract_options!
  attrib = args.first.to_s
  
  if self.respond_to?("by_#{attrib}")
    validate "uniqueness_of_#{attrib}".to_sym
    define_method "uniqueness_of_#{attrib}" do
      same = self.class.find(:conditions => { attrib => self.send(attrib) })
      if same && same.id != self.id
        self.errors.add(attrib, options[:message] || :taken)
      end
    end
  else
    Rails.logger.warn "WARNING you tried to validate uniqueness of #{attrib} but no view named 'by_#{attrib}' exists. Validation could not be added."
  end
end