Class: IntercomRails::Proxy::Company

Inherits:
Proxy
  • Object
show all
Defined in:
lib/intercom-rails/proxy/company.rb

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, #standard_data, #to_hash

Constructor Details

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

Class Method Details

.companies_for_user(user) ⇒ Object


14
15
16
17
18
19
20
# File 'lib/intercom-rails/proxy/company.rb', line 14

def self.companies_for_user(user)
  return unless config(:user).company_association.present?
  companies = config(:user).company_association.call(user.user)
  return unless companies.kind_of?(Array)

  companies.map { |company| new(company) }.select { |company_proxy| company_proxy.valid? }
end

.current_in_context(search_object) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/intercom-rails/proxy/company.rb', line 22

def self.current_in_context(search_object)
  begin
    if config.current.present?
      company_proxy = new(search_object.instance_eval(&config.current), search_object)
      return company_proxy if company_proxy.valid?
    end
  rescue NameError
  end

  raise NoCompanyFoundError
end

Instance Method Details

#valid?Boolean


34
35
36
# File 'lib/intercom-rails/proxy/company.rb', line 34

def valid?
  company.present? && identity_present?
end