Class: IntercomRails::Proxy::User
- Inherits:
-
Proxy
- Object
- Proxy
- IntercomRails::Proxy::User
show all
- Defined in:
- lib/intercom-rails/proxy/user.rb
Constant Summary
collapse
- PREDEFINED_POTENTIAL_USER_OBJECTS =
[
Proc.new { current_user },
Proc.new { @user }
]
Instance Attribute Summary
Attributes inherited from Proxy
#proxied_object, #search_object
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Proxy
class_string, #custom_data, inherited, #initialize, #to_hash
Class Method Details
.current_in_context(search_object) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/intercom-rails/proxy/user.rb', line 29
def self.current_in_context(search_object)
potential_user_objects.each do |potential_object|
begin
user_proxy = new(search_object.instance_eval(&potential_object), search_object)
return user_proxy if user_proxy.valid?
rescue NameError
next
end
end
raise NoUserFoundError
end
|
.potential_user_objects ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/intercom-rails/proxy/user.rb', line 17
def self.potential_user_objects
if config.current.present?
if config.current.kind_of?(Array)
config.current.map { |user| Proc.new { instance_eval &user } }
else
[Proc.new { instance_eval &IntercomRails.config.user.current }]
end
else
PREDEFINED_POTENTIAL_USER_OBJECTS
end
end
|
Instance Method Details
#standard_data ⇒ Object
42
43
44
45
46
|
# File 'lib/intercom-rails/proxy/user.rb', line 42
def standard_data
super.tap do |hsh|
hsh[:user_id] = hsh.delete(:id) if hsh.has_key?(:id)
end
end
|
#valid? ⇒ Boolean
48
49
50
51
52
|
# File 'lib/intercom-rails/proxy/user.rb', line 48
def valid?
return false if user.blank? || user.respond_to?(:new_record?) && user.new_record?
return false if config.user.exclude_if.present? && config.user.exclude_if.call(user)
identity_present?
end
|