Module: Devise::Orm::DataMapper

Includes:
Schema
Defined in:
lib/devise/orm/data_mapper.rb

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Schema

#authenticatable, #confirmable, #database_authenticatable, #lockable, #recoverable, #rememberable, #token_authenticatable, #trackable

Class Method Details

.included_modules_hook(klass) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/devise/orm/data_mapper.rb', line 14

def self.included_modules_hook(klass)
  klass.send :extend,  self
  klass.send :include, InstanceMethods

  yield

  klass.devise_modules.each do |mod|
    klass.send(mod) if klass.respond_to?(mod)
  end
end

Instance Method Details

#after_create(*args) ⇒ Object



37
38
39
# File 'lib/devise/orm/data_mapper.rb', line 37

def after_create(*args)
  wrap_hook(:after, *args)
end

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

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



69
70
71
72
73
74
75
76
77
78
# File 'lib/devise/orm/data_mapper.rb', line 69

def apply_schema(name, type, options={})
  return unless Devise.apply_schema

  SCHEMA_OPTIONS.each do |old_key, new_key|
    next unless options.key?(old_key)
    options[new_key] = options.delete(old_key)
  end

  property name, type, options
end

#before_create(*args) ⇒ Object

Hooks for confirmable



33
34
35
# File 'lib/devise/orm/data_mapper.rb', line 33

def before_create(*args)
  wrap_hook(:before, *args)
end

#find(*args) ⇒ Object

Add ActiveRecord like finder



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/devise/orm/data_mapper.rb', line 55

def find(*args)
  options = args.extract_options!
  case args.first
    when :first
      first(options)
    when :all
      all(options)
    else
      get(*args)
  end
end

#wrap_hook(action, *args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/devise/orm/data_mapper.rb', line 41

def wrap_hook(action, *args)
  options = args.extract_options!

  args.each do |callback|
    send action, :create, callback
    class_eval "      def \#{callback}\n        super if \#{options[:if] || true}\n      end\n    METHOD\n  end\nend\n", __FILE__, __LINE__ + 1