Module: Devise::Orm::MongoMapper::Schema

Includes:
Schema
Defined in:
lib/devise/orm/mongo_mapper/schema.rb

Constant Summary collapse

SCHEMA_OPTIONS =
{
  :null  => :required,
  :limit => :length
}

Instance Method Summary collapse

Instance Method Details

#apply_devise_schema(name, type, options = {}) ⇒ Object

Tell how to apply schema methods. This automatically maps :limit to :length and :null to :required.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/devise/orm/mongo_mapper/schema.rb', line 27

def apply_devise_schema(name, type, options={})
  SCHEMA_OPTIONS.each do |old_key, new_key|
    next unless options.key?(old_key)
    if :null == old_key
      # :required is opposite of :null
      options[new_key] = !options.delete(old_key)
    else
      options[new_key] = options.delete(old_key)
    end
  end
  
  options.delete(:default) if options[:default].nil?
  required_option = options.delete(:required)          
  length_option = options.delete(:length)          

  type = Time if type == DateTime         

  key name, type, options
  
  counter = ::MongoMapper::ValidationUtil.inc_counter

  handle_email(name, counter) if name == :email          
  handle_length(name, counter, length_option) if length_option
  handle_required(name, counter) if required_option                               
end