intercom-rails 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 274c2855076beb153ba6dcf5ecdc639bcac1a2515bfe74a7042b84df61eab363
4
- data.tar.gz: 59e0d09f3dca2b46db7e6e3829d39a89f75eef845c1608f690e87bad41505f0f
3
+ metadata.gz: 2e7d544e693716ec8e6927a28aa46d01d2c360544bfb0c9816193013e1d9686c
4
+ data.tar.gz: 732324518526f63c2202be3521a890f77d90d26953e103d0fc47ebdafd27f945
5
5
  SHA512:
6
- metadata.gz: eebe74df506580a99a1fbe68857ab6c86c140e1db905c4cc96307aa0baa984b2d5efcf852eff43baaf7e6edb4b0937c2340a26b56f602339014478bf92e5c4bd
7
- data.tar.gz: f3d98e2f4fa9083ba632faa4852028656e20c4b4c14c931dc3caa6dea429957efd9f0402b84be390dd2a97ee9bf0d002622206f455835277844d13f69e5b8aff
6
+ metadata.gz: 4b3b36ca475257f4c2ebdd89f93a517124e686ffc5b51f8c081dc96cabc4e47cf19b23ab0f34eb28f002dd116f186704701e0fd6fcf514bc09a207aa2d35f943
7
+ data.tar.gz: fdaafd9ba64ea6cdf9c9a7b681834b1cb1cd5b7cba4d1402b4a9c8d944ff4b792595482957bd7c106986e4add9cd1ec7fba670643de0518e85b2b290fae0bf2e
data/README.md CHANGED
@@ -47,7 +47,7 @@ If things are not working make sure that:
47
47
 
48
48
  * You've generated a config file with your `app_id` as detailed above.
49
49
  * Your user object responds to an `id` or `email` method.
50
- * Your current user is accessible in your controllers as `current_user` or `@user`, if not in `config/initializers/intercom.rb`:
50
+ * Your current user is accessible in your controllers as `current_user`. If it is not, set it in `config/initializers/intercom.rb`:
51
51
  ```ruby
52
52
  config.user.current = Proc.new { current_user_object }
53
53
  ```
@@ -24,7 +24,7 @@ module IntercomRails
24
24
  end
25
25
 
26
26
  def valid?
27
- return false if company.blank? || company.respond_to?(:new_record?) && company.new_record?
27
+ return false if company.blank? || unsaved?
28
28
  return false if config.company.exclude_if.present? && config.company.exclude_if.call(company)
29
29
  company.present? && identity_present?
30
30
  end
@@ -9,10 +9,7 @@ module IntercomRails
9
9
  proxy_delegator :name
10
10
  proxy_delegator :created_at
11
11
 
12
- PREDEFINED_POTENTIAL_USER_OBJECTS = [
13
- Proc.new { current_user },
14
- Proc.new { @user }
15
- ]
12
+ PREDEFINED_POTENTIAL_USER_OBJECTS = [Proc.new { current_user }]
16
13
 
17
14
  def self.potential_user_objects
18
15
  if config.current.present?
@@ -46,7 +43,7 @@ module IntercomRails
46
43
  end
47
44
 
48
45
  def valid?
49
- return false if user.blank? || user.respond_to?(:new_record?) && user.new_record?
46
+ return false if user.blank? || unsaved?
50
47
  return false if excluded?
51
48
  identity_present?
52
49
  end
@@ -71,6 +71,13 @@ module IntercomRails
71
71
  config.send(variable_name).present?
72
72
  end
73
73
 
74
+ def unsaved?
75
+ return proxied_object.new_record? if proxied_object.respond_to?(:new_record?)
76
+ return !proxied_object.persisted? if proxied_object.respond_to?(:persisted?)
77
+ return proxied_object.new? if proxied_object.respond_to?(:new?)
78
+ false
79
+ end
80
+
74
81
  def identity_present?
75
82
  self.class.identity_attributes.any? { |attribute_name| (proxied_object.is_a?(Hash) && proxied_object[attribute_name].present?) || (proxied_object.respond_to?(attribute_name) && proxied_object.send(attribute_name).present?) }
76
83
  end
@@ -54,7 +54,7 @@ module IntercomRails
54
54
  return false if user_details[:excluded_user] == true
55
55
  valid = user_details[:app_id].present?
56
56
  unless @show_everywhere
57
- valid = valid && (user_details[:user_id] || user_details[:email]).present?
57
+ valid = valid && @has_identity
58
58
  end
59
59
  if nonce
60
60
  valid = valid && valid_nonce?
@@ -146,6 +146,8 @@ module IntercomRails
146
146
  @user_details = @user_details.with_indifferent_access.tap do |u|
147
147
  [:email, :name, :user_id].each { |k| u.delete(k) if u[k].nil? }
148
148
 
149
+ @has_identity = (u[:user_id] || u[:email]).present?
150
+
149
151
  if secret.present?
150
152
  if jwt_enabled && u[:user_id].present?
151
153
  u[:intercom_user_jwt] ||= generate_jwt
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -20,9 +20,9 @@ module Intercom
20
20
  introduction = <<-desc
21
21
  Intercom will automatically insert its javascript before the closing '</body>'
22
22
  tag on every page where it can find a logged-in user. Intercom by default
23
- looks for logged-in users, in the controller, via 'current_user' and '@user'.
23
+ looks for logged-in users, in the controller, via 'current_user'.
24
24
 
25
- Is the logged-in user accessible via either 'current_user' or '@user'? [Yn]
25
+ Is the logged-in user accessible via 'current_user'? [Yn]
26
26
  desc
27
27
 
28
28
  print "#{introduction.strip} "
@@ -27,7 +27,7 @@ IntercomRails.config do |config|
27
27
 
28
28
  # == Current user method/variable
29
29
  # The method/variable that contains the logged in user in your controllers.
30
- # If it is `current_user` or `@user`, then you can ignore this
30
+ # If it is `current_user`, then you can ignore this
31
31
  #
32
32
  <%- if @current_user -%>
33
33
  config.user.current = Proc.new { <%= @current_user %> }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  requirements: []
203
- rubygems_version: 4.0.3
203
+ rubygems_version: 4.0.11
204
204
  specification_version: 4
205
205
  summary: Rails helper for emitting javascript script tags for Intercom
206
206
  test_files: []