More improvements in DataMapper support front.
This commit is contained in:
parent
f3d5c1af22
commit
fddf95fe0a
|
@ -1,4 +1,5 @@
|
|||
* enhancements
|
||||
* Added DataMapper support
|
||||
* Remove store_location from authenticatable strategy and add it to failure app
|
||||
* Allow a strategy to be placed after authenticatable
|
||||
* [#45] Do not rely attribute? methods, since they are not added on Datamapper
|
||||
|
|
|
@ -37,7 +37,7 @@ Devise.setup do |config|
|
|||
# Configure the e-mail address which will be shown in DeviseMailer.
|
||||
# config.mailer_sender = "foo.bar@yourapp.com"
|
||||
|
||||
# Configure the ORM. Supports :active_record and :mongo_mapper
|
||||
# Configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
|
||||
# config.orm = :active_record
|
||||
|
||||
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
||||
|
|
|
@ -87,11 +87,10 @@ module Devise
|
|||
# Attempt to find a user by it's email. If not user is found, returns a
|
||||
# new user with an email not found error.
|
||||
def find_or_initialize_with_error_by_email(email)
|
||||
perishable = find_or_initialize_by_email(email)
|
||||
if perishable.new_record?
|
||||
perishable.errors.add(:email, :not_found, :default => 'not found')
|
||||
end
|
||||
perishable
|
||||
attributes = { :email => email }
|
||||
record = find(:first, :conditions => attributes) || new(attributes)
|
||||
record.errors.add(:email, :not_found, :default => 'not found') if record.new_record?
|
||||
record
|
||||
end
|
||||
|
||||
# Hook to serialize user into session. Overwrite if you want.
|
||||
|
@ -103,7 +102,7 @@ module Devise
|
|||
def serialize_from_session(keys)
|
||||
klass, id = keys
|
||||
raise "#{self} cannot serialize from #{klass} session since it's not its ancestors" unless klass <= self
|
||||
klass.find_by_id(id)
|
||||
klass.find(:first, :conditions => { :id => id })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
module Devise
|
||||
module Orm
|
||||
module DataMapper
|
||||
def self.included_modules_hook(klass, modules)
|
||||
klass.send :extend, self
|
||||
|
||||
# DataMapper validations have a completely different API
|
||||
if modules.include?(:validatable) && !klass.respond_to?(:validates_presence_of)
|
||||
raise ":validatable is not supported in DataMapper, please craft your validations by hand"
|
||||
end
|
||||
|
||||
modules.each do |mod|
|
||||
klass.send(mod)
|
||||
end
|
||||
end
|
||||
|
||||
include Devise::Schema
|
||||
|
||||
SCHEMA_OPTIONS = {
|
||||
:null => :nullable,
|
||||
:limit => :length
|
||||
}
|
||||
|
||||
# Hooks for confirmable
|
||||
def before_create(*args)
|
||||
before :create, *args
|
||||
end
|
||||
|
||||
def after_create(*args)
|
||||
after :create, *args
|
||||
end
|
||||
|
||||
# Add ActiveRecord like finder
|
||||
def find(*args)
|
||||
options = args.extract_options!
|
||||
case args.first
|
||||
when :first
|
||||
first(options.merge(options.delete(:conditions)))
|
||||
when :all
|
||||
all(options.merge(options.delete(:conditions)))
|
||||
else
|
||||
get(*args)
|
||||
end
|
||||
end
|
||||
|
||||
# Tell how to apply schema methods. This automatically maps :limit to
|
||||
# :length and :null to :nullable.
|
||||
def apply_schema(name, type, options={})
|
||||
return unless Devise.apply_schema
|
||||
|
||||
SCHEMA_OPTIONS.each do |old_key, new_key|
|
||||
next unless options[old_key]
|
||||
options[new_key] = options.delete(old_key)
|
||||
end
|
||||
|
||||
property name, type, options
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
DataMapper::Model.send(:include, Devise::Models)
|
|
@ -1,7 +1,6 @@
|
|||
module Devise
|
||||
module Orm
|
||||
module MongoMapper
|
||||
# Include attributes modules and set the proper ones.
|
||||
def self.included_modules_hook(klass, modules)
|
||||
klass.send :extend, self
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ module Devise
|
|||
end
|
||||
|
||||
# Overwrite with specific modification to create your own schema.
|
||||
def apply_schema(name, tupe, options={})
|
||||
def apply_schema(name, type, options={})
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue