Sha256: 35d41923ebb750833bfbbec143f9ced0d49036833733b67b70db4aa8b2c20508

Contents?: true

Size: 1.83 KB

Versions: 30

Compression:

Stored size: 1.83 KB

Contents

module Devise
  module Orm
    module DataMapper
      module InstanceMethods
        def save(flag=nil)
          if flag == false
            save!
          else
            super()
          end
        end
      end

      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

      include Devise::Schema

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

      # Hooks for confirmable
      def before_create(*args)
        wrap_hook(:before, *args)
      end

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

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

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

      # Add ActiveRecord like finder
      def find(*args)
        options = args.extract_options!
        case args.first
          when :first
            first(options)
          when :all
            all(options)
          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.key?(old_key)
          options[new_key] = options.delete(old_key)
        end

        property name, type, options
      end
    end
  end
end

DataMapper::Model.send(:include, Devise::Models)

Version data entries

30 entries across 25 versions & 7 rubygems

Version Path
devise-1.0.5 lib/devise/orm/data_mapper.rb
devise-1.0.4 lib/devise/orm/data_mapper.rb
devise-1.0.3 lib/devise/orm/data_mapper.rb
devise-1.1.pre2 lib/devise/orm/data_mapper.rb
glennr-devise-1.0.1.1 lib/devise/orm/data_mapper.rb
glennr-devise-1.0.1 lib/devise/orm/data_mapper.rb
devise-1.0.2 lib/devise/orm/data_mapper.rb
devise-1.1.pre lib/devise/orm/data_mapper.rb
devise-1.0.1 lib/devise/orm/data_mapper.rb
devise-1.0.0 lib/devise/orm/data_mapper.rb