Module: Wristband::ClassMethods

Defined in:
lib/wristband.rb

Instance Method Summary collapse

Instance Method Details

#wristband(options = {}) ⇒ Object



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/wristband.rb', line 21

def wristband(options={})
  options[:login_with]            ||= [:email]
  options[:before_authentication] ||= []
  options[:after_authentication]  ||= []
  options[:has_authorities]       ||= false
  options[:roles]                 ||= []
  options[:legacy_password]       ||= {}
  options[:encryption_type]       ||= :bcrypt

  class_eval do
    include Wristband::UserExtensions
    
    options[:password_column] ||= :encrypted_password
    
    # These two are used on the login form
    attr_accessor :password
    attr_accessor :password_confirmation
    
    before_save :encrypt_password
    
    # Add roles
    unless options[:roles].blank?
      options[:roles].each do |role|
        define_method "is_#{role}?" do
          self.role.to_s == role.to_s
        end
      end
    end
    
    class << self
      attr_accessor :wristband
    end
  end
  
  self.wristband = {
    :login_with_fields            => [options[:login_with]].flatten,
    :before_authentication_chain  => [options[:before_authentication]].flatten,
    :after_authentication_chain   => [options[:after_authentication]].flatten,
    :password_column              => options[:password_column],
    :roles                        => options[:roles],
    :legacy_password              => options[:legacy_password],
    :encryption_type              => options[:encryption_type]
  }
  
  if options[:has_authorities]
    self.wristband[:authority_class] = UtilityMethods.interpret_class_specification(self, options[:has_authorities])
  end
end