Module: AuthSlice::Adapter::Datamapper

Defined in:
app/models/adapter/datamapper.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.create_user_modelObject



8
9
10
11
12
13
14
# File 'app/models/adapter/datamapper.rb', line 8

def self.create_user_model
  Object.class_eval <<-end_eval
    class ::AuthSlice::User
      include AuthSlice::Adapter::Datamapper
    end
  end_eval
end

.included(base) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/adapter/datamapper.rb', line 16

def self.included(base)
  base.class_eval do
    include ::DataMapper::Resource
    include AuthSlice::BaseModel
    extend ClassMethods
    
    storage_names[:default] = 'users'
    
    property :id, Integer, :serial => true
    property :name, String, :length => 3..40, :nullable => false
    property :username, String, :length => 3..40, :nullable => false
    property :email, String, :format => :email_address, :nullable => false
    property :crypted_password, String, :length => 40
    property :salt, String, :length => 40
    property :remember_token_expires_at, Date
    property :remember_token, String
    property :created_at, DateTime
    property :updated_at, DateTime
  
    validates_is_unique :username, :email
    validates_length :password, :in => 4..40, :if => :password_required?
    validates_is_confirmed :password, :groups => :create

    before :save, :encrypt_password
    
    def username=(value)
      attribute_set(:username, value.downcase) if value
    end
  end
end