Class: IntercomRails::Proxy::User

Inherits:
Proxy
  • Object
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

Constructor Details

This class inherits a constructor from IntercomRails::Proxy::Proxy

Class Method Details

.current_in_context(search_object) ⇒ Object

Raises:


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/intercom-rails/proxy/user.rb', line 25

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_objectsObject


17
18
19
20
21
22
23
# File 'lib/intercom-rails/proxy/user.rb', line 17

def self.potential_user_objects
  if config.current.present?
    [Proc.new { instance_eval &IntercomRails.config.user.current }]
  else
    PREDEFINED_POTENTIAL_USER_OBJECTS
  end
end

Instance Method Details

#standard_dataObject


38
39
40
41
42
# File 'lib/intercom-rails/proxy/user.rb', line 38

def standard_data
  super.tap do |hsh|
    hsh[:user_id] = hsh.delete(:id) if hsh.has_key?(:id)
  end
end

#valid?Boolean

Returns:

  • (Boolean)

44
45
46
47
48
# File 'lib/intercom-rails/proxy/user.rb', line 44

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