Module: Devise::Orm::DataMapper::Schema

Includes:
Schema
Defined in:
lib/devise/orm/data_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.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/devise/orm/data_mapper/schema.rb', line 17

def apply_devise_schema(name, type, options={})
  return false if properties[name]
  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

  if String == type && !options[:length]
    options[:length] = 255
  end

  options[:required] ||= false

  options.delete(:default) if options[:default].nil?
  property name, type, options
end