/
foundation.rb
69 lines (62 loc) · 2.42 KB
/
foundation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Authlogic
module Session
# Sort of like an interface, it sets the foundation for the class, such as the required methods. This also allows
# other modules to overwrite methods and call super on them. It's also a place to put "utility" methods used
# throughout Authlogic.
module Foundation
def self.included(klass)
klass.class_eval do
class_attribute :acts_as_authentic_config
self.acts_as_authentic_config ||= {}
extend ClassMethods
include InstanceMethods
end
end
module ClassMethods
private
def rw_config(key, value, default_value = nil, read_value = nil)
if value == read_value
return acts_as_authentic_config[key] if acts_as_authentic_config.include?(key)
rw_config(key, default_value) unless default_value.nil?
else
config = acts_as_authentic_config.clone
config[key] = value
self.acts_as_authentic_config = config
value
end
end
end
module InstanceMethods
def initialize(*args)
self.credentials = args
end
# The credentials you passed to create your session. See credentials= for more info.
def credentials
[]
end
# Set your credentials before you save your session. You can pass a hash of credentials:
#
# session.credentials = {:login => "my login", :password => "my password", :remember_me => true}
#
# or you can pass an array of objects:
#
# session.credentials = [my_user_object, true]
#
# and if you need to set an id, just pass it last. This value need be the last item in the array you pass, since the id is something that
# you control yourself, it should never be set from a hash or a form. Examples:
#
# session.credentials = [{:login => "my login", :password => "my password", :remember_me => true}, :my_id]
# session.credentials = [my_user_object, true, :my_id]
def credentials=(values)
end
def inspect
"#<#{self.class.name}: #{credentials.blank? ? "no credentials provided" : credentials.inspect}>"
end
private
def build_key(last_part)
last_part
end
end
end
end
end