Class: IntercomRails::Proxy::Proxy

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

Direct Known Subclasses

Company, User

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_to_proxy, search_object = nil) ⇒ Proxy


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

def initialize(object_to_proxy, search_object = nil)
  @search_object = search_object
  @proxied_object = instance_variable_set(:"@#{type}", object_to_proxy)
end

Instance Attribute Details

#proxied_objectObject (readonly)

Returns the value of attribute proxied_object


17
18
19
# File 'lib/intercom-rails/proxy.rb', line 17

def proxied_object
  @proxied_object
end

#search_objectObject (readonly)

Returns the value of attribute search_object


17
18
19
# File 'lib/intercom-rails/proxy.rb', line 17

def search_object
  @search_object
end

Class Method Details

.class_stringObject


7
8
9
# File 'lib/intercom-rails/proxy.rb', line 7

def self.class_string
  self.to_s.split('::').last
end

.inherited(subclass) ⇒ Object


11
12
13
14
15
# File 'lib/intercom-rails/proxy.rb', line 11

def self.inherited(subclass)
  subclass.class_eval do
    attr_reader class_string.downcase.to_s
  end
end

Instance Method Details

#custom_dataObject


48
49
50
# File 'lib/intercom-rails/proxy.rb', line 48

def custom_data
  custom_data_from_config.merge custom_data_from_request
end

#standard_dataObject


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/intercom-rails/proxy.rb', line 34

def standard_data
  proxied_values = self.class.standard_data_proxy_attributes.reduce({}) do |hsh, attribute_name|
    hsh[attribute_name] = send(attribute_name) if send(attribute_name).present?
    hsh
  end

  configured_values = self.class.standard_data_config_attributes.reduce({}) do |hsh, attribute_name|
    next(hsh) unless config_variable_set?(attribute_name)
    hsh.merge(attribute_name => send(attribute_name))
  end

  proxied_values.merge(configured_values)
end

#to_hashObject


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

def to_hash
  data = standard_data.merge(custom_data)
  [:id, :user_id].each do |id_key|
    if(data[id_key] && !data[id_key].is_a?(Numeric))
      data[id_key] = data[id_key].to_s
    end
  end
  DateHelper.convert_dates_to_unix_timestamps(data)
end