userlist-rails 0.5.3 → 0.6.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 +4 -4
- data/README.md +18 -4
- data/lib/userlist/rails.rb +6 -0
- data/lib/userlist/rails/transform.rb +1 -1
- data/lib/userlist/rails/transforms/company.rb +25 -11
- data/lib/userlist/rails/transforms/has_relationships.rb +35 -0
- data/lib/userlist/rails/transforms/relationship.rb +6 -6
- data/lib/userlist/rails/transforms/user.rb +25 -11
- data/lib/userlist/rails/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1541bb4907f73b3f85ffd2a97ca5d3040cb5128ee4dfbf6a8c5dfc1bf05c5afe
|
4
|
+
data.tar.gz: 4e0212563099467fa99ea690fde210dd947ec89995f095e95a7df72b6f84171a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83520dc930b013536d4a3278326ee07f37fdae4a303e0ea2d935ca38d168358eb2d9011eeb08902850ac88b4ac0ae6f337c3133826a1eeeaa6ca0d0740ca5c3a
|
7
|
+
data.tar.gz: eedce9ed77e9464da3da6c6f00306b252c69bd39ac95cc2cbf43247a852c9a29d763198e4ad69fcc179a10008e079d9889d953a41188131c837550a93132aec5
|
data/README.md
CHANGED
@@ -151,7 +151,7 @@ end
|
|
151
151
|
To manually send company data into Userlist, use the `Userlist::Push.companies.push` method.
|
152
152
|
|
153
153
|
```ruby
|
154
|
-
Userlist::Push.companies.push(
|
154
|
+
Userlist::Push.companies.push(company)
|
155
155
|
```
|
156
156
|
|
157
157
|
It's also possible to customize the payload sent to Userlist by passing a hash instead of the company object.
|
@@ -166,14 +166,14 @@ Userlist::Push.companies.push(identifier: company.id, name: company.name, proper
|
|
166
166
|
For cases where you don't want to send specific company to Userlist you can add a `userlist_push?` method. Whenever this method doesn't return a falsey value, this company will not be sent to Userlist. This also applies to any events or relationships this company is involved in.
|
167
167
|
|
168
168
|
```ruby
|
169
|
-
class
|
169
|
+
class Account < ApplicationRecord
|
170
170
|
def userlist_push?
|
171
|
-
!deleted? &&
|
171
|
+
!deleted? && active_subscription?
|
172
172
|
end
|
173
173
|
end
|
174
174
|
```
|
175
175
|
|
176
|
-
#### Deleting
|
176
|
+
#### Deleting companies
|
177
177
|
|
178
178
|
It's also possible to delete a company from Userlist, using the `Userlist::Push.companies.delete` method.
|
179
179
|
|
@@ -233,6 +233,20 @@ class User < ApplicationRecord
|
|
233
233
|
end
|
234
234
|
```
|
235
235
|
|
236
|
+
If you don't have a dedicated model describing the relationship, you can return a hash including both the user and the company model.
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
class User < ApplicationRecord
|
240
|
+
def userlist_relationships
|
241
|
+
[
|
242
|
+
{
|
243
|
+
user: self,
|
244
|
+
company: account
|
245
|
+
}
|
246
|
+
]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
```
|
236
250
|
|
237
251
|
#### Ignoring relationships
|
238
252
|
|
data/lib/userlist/rails.rb
CHANGED
@@ -59,6 +59,12 @@ module Userlist
|
|
59
59
|
from.reflect_on_all_associations.find { |r| r.class_name == to.to_s }
|
60
60
|
end
|
61
61
|
|
62
|
+
def self.find_association_between(from, to)
|
63
|
+
return unless association = Userlist::Rails.find_reflection(from, to)
|
64
|
+
|
65
|
+
association.through_reflection || association
|
66
|
+
end
|
67
|
+
|
62
68
|
def self.setup_callbacks(model, scope)
|
63
69
|
return if model.instance_variable_get(:@userlist_callbacks_registered)
|
64
70
|
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'userlist/rails/transform'
|
2
|
+
require 'userlist/rails/transforms/has_relationships'
|
2
3
|
|
3
4
|
module Userlist
|
4
5
|
module Rails
|
5
6
|
module Transforms
|
6
7
|
class Company < Userlist::Rails::Transform
|
8
|
+
include HasRelationships
|
9
|
+
|
7
10
|
def self.attributes
|
8
11
|
@attributes ||= [
|
9
12
|
:identifier,
|
@@ -14,26 +17,37 @@ module Userlist
|
|
14
17
|
]
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
|
20
|
+
def default_identifier
|
21
|
+
"#{model.class.name}-#{model.id}".parameterize
|
19
22
|
end
|
20
23
|
|
21
|
-
def
|
22
|
-
|
24
|
+
def default_properties
|
25
|
+
{}
|
23
26
|
end
|
24
27
|
|
25
|
-
def
|
26
|
-
|
28
|
+
def default_name
|
29
|
+
model.try(:name)
|
30
|
+
end
|
27
31
|
|
28
|
-
|
32
|
+
def default_signed_up_at
|
33
|
+
model.try(:created_at)
|
29
34
|
end
|
30
35
|
|
31
|
-
|
32
|
-
|
36
|
+
private
|
37
|
+
|
38
|
+
def build_relationship(record)
|
39
|
+
{
|
40
|
+
user: record,
|
41
|
+
company: model
|
42
|
+
}
|
33
43
|
end
|
34
44
|
|
35
|
-
def
|
36
|
-
|
45
|
+
def relationship_from
|
46
|
+
config.company_model
|
47
|
+
end
|
48
|
+
|
49
|
+
def relationship_to
|
50
|
+
config.user_model
|
37
51
|
end
|
38
52
|
end
|
39
53
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'userlist/rails/transform'
|
2
|
+
|
3
|
+
module Userlist
|
4
|
+
module Rails
|
5
|
+
module Transforms
|
6
|
+
module HasRelationships
|
7
|
+
def default_relationships
|
8
|
+
return unless association = Userlist::Rails.find_association_between(relationship_from, relationship_to)
|
9
|
+
|
10
|
+
records = model.try(association.name)
|
11
|
+
|
12
|
+
if association.klass == config.relationship_model
|
13
|
+
records
|
14
|
+
elsif association.klass == relationship_to
|
15
|
+
Array.wrap(records).map { |record| build_relationship(record) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build_relationship(_record)
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
def relationship_to
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
|
29
|
+
def relationship_from
|
30
|
+
raise NotImplementedError
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -12,20 +12,20 @@ module Userlist
|
|
12
12
|
]
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def default_properties
|
16
|
+
{}
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def default_user
|
20
20
|
user_method = Userlist::Rails.find_reflection(config.relationship_model, config.user_model)&.name
|
21
21
|
|
22
|
-
|
22
|
+
user_method && model.try(user_method)
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def default_company
|
26
26
|
company_method = Userlist::Rails.find_reflection(config.relationship_model, config.company_model)&.name
|
27
27
|
|
28
|
-
|
28
|
+
company_method && model.try(company_method)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'userlist/rails/transform'
|
2
|
+
require 'userlist/rails/transforms/has_relationships'
|
2
3
|
|
3
4
|
module Userlist
|
4
5
|
module Rails
|
5
6
|
module Transforms
|
6
7
|
class User < Userlist::Rails::Transform
|
8
|
+
include HasRelationships
|
9
|
+
|
7
10
|
def self.attributes
|
8
11
|
@attributes ||= [
|
9
12
|
:identifier,
|
@@ -14,26 +17,37 @@ module Userlist
|
|
14
17
|
]
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
|
20
|
+
def default_identifier
|
21
|
+
"#{model.class.name}-#{model.id}".parameterize
|
19
22
|
end
|
20
23
|
|
21
|
-
def
|
22
|
-
|
24
|
+
def default_properties
|
25
|
+
{}
|
23
26
|
end
|
24
27
|
|
25
|
-
def
|
26
|
-
|
28
|
+
def default_email
|
29
|
+
model.try(:email)
|
30
|
+
end
|
27
31
|
|
28
|
-
|
32
|
+
def default_signed_up_at
|
33
|
+
model.try(:created_at)
|
29
34
|
end
|
30
35
|
|
31
|
-
|
32
|
-
|
36
|
+
private
|
37
|
+
|
38
|
+
def build_relationship(record)
|
39
|
+
{
|
40
|
+
user: model,
|
41
|
+
company: record
|
42
|
+
}
|
33
43
|
end
|
34
44
|
|
35
|
-
def
|
36
|
-
|
45
|
+
def relationship_from
|
46
|
+
config.user_model
|
47
|
+
end
|
48
|
+
|
49
|
+
def relationship_to
|
50
|
+
config.company_model
|
37
51
|
end
|
38
52
|
end
|
39
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: userlist-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benedikt Deicke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- lib/userlist/rails/tasks/userlist.rake
|
190
190
|
- lib/userlist/rails/transform.rb
|
191
191
|
- lib/userlist/rails/transforms/company.rb
|
192
|
+
- lib/userlist/rails/transforms/has_relationships.rb
|
192
193
|
- lib/userlist/rails/transforms/relationship.rb
|
193
194
|
- lib/userlist/rails/transforms/user.rb
|
194
195
|
- lib/userlist/rails/version.rb
|