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
# File 'lib/devise/orm/data_mapper/schema.rb', line 17

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?
  property name, type, options
end