userlist-rails 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +22 -0
- data/.rubocop.yml +4 -2
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +1 -1
- data/README.md +207 -21
- data/lib/userlist/rails.rb +104 -6
- data/lib/userlist/rails/config.rb +15 -3
- data/lib/userlist/rails/extensions/company.rb +30 -0
- data/lib/userlist/rails/extensions/event.rb +10 -3
- data/lib/userlist/rails/extensions/relationship.rb +30 -0
- data/lib/userlist/rails/extensions/user.rb +30 -0
- data/lib/userlist/rails/helpers.rb +2 -4
- data/lib/userlist/rails/railtie.rb +24 -10
- data/lib/{tasks → userlist/rails/tasks}/userlist.rake +5 -5
- data/lib/userlist/rails/transform.rb +42 -0
- data/lib/userlist/rails/transforms/company.rb +55 -0
- data/lib/userlist/rails/transforms/has_relationships.rb +35 -0
- data/lib/userlist/rails/transforms/relationship.rb +33 -0
- data/lib/userlist/rails/transforms/user.rb +55 -0
- data/lib/userlist/rails/version.rb +1 -1
- data/userlist-rails.gemspec +6 -5
- metadata +41 -22
- data/.travis.yml +0 -7
- data/lib/userlist/rails/company.rb +0 -45
- data/lib/userlist/rails/extensions/resource.rb +0 -35
- data/lib/userlist/rails/user.rb +0 -51
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'userlist/rails/transform'
|
2
|
+
require 'userlist/rails/transforms/has_relationships'
|
3
|
+
|
4
|
+
module Userlist
|
5
|
+
module Rails
|
6
|
+
module Transforms
|
7
|
+
class User < Userlist::Rails::Transform
|
8
|
+
include HasRelationships
|
9
|
+
|
10
|
+
def self.attributes
|
11
|
+
@attributes ||= [
|
12
|
+
:identifier,
|
13
|
+
:properties,
|
14
|
+
:relationships,
|
15
|
+
:email,
|
16
|
+
:signed_up_at
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_identifier
|
21
|
+
"#{model.class.name}-#{model.id}".parameterize
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_properties
|
25
|
+
{}
|
26
|
+
end
|
27
|
+
|
28
|
+
def default_email
|
29
|
+
model.try(:email)
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_signed_up_at
|
33
|
+
model.try(:created_at)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def build_relationship(record)
|
39
|
+
{
|
40
|
+
user: model,
|
41
|
+
company: record
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def relationship_from
|
46
|
+
config.user_model
|
47
|
+
end
|
48
|
+
|
49
|
+
def relationship_to
|
50
|
+
config.company_model
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/userlist-rails.gemspec
CHANGED
@@ -7,9 +7,9 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'userlist-rails'
|
8
8
|
spec.version = Userlist::Rails::VERSION
|
9
9
|
spec.authors = ['Benedikt Deicke']
|
10
|
-
spec.email = ['benedikt@userlist.
|
10
|
+
spec.email = ['benedikt@userlist.com']
|
11
11
|
spec.homepage = 'https://github.com/userlistio/userlist-rails'
|
12
|
-
spec.summary = 'Rails integration for Userlist
|
12
|
+
spec.summary = 'Rails integration for Userlist'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -19,16 +19,17 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.required_ruby_version = '>= 2.
|
22
|
+
spec.required_ruby_version = '>= 2.4'
|
23
23
|
|
24
24
|
spec.add_dependency 'activesupport', '>= 5.0'
|
25
25
|
spec.add_dependency 'railties', '>= 5.0'
|
26
|
-
spec.add_dependency 'userlist', '~> 0.
|
26
|
+
spec.add_dependency 'userlist', '~> 0.5'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'actionpack', '>= 5.0'
|
29
|
+
spec.add_development_dependency 'activerecord', '>= 5.0'
|
29
30
|
spec.add_development_dependency 'bundler', '>= 1.15'
|
30
31
|
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
|
31
32
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
33
|
spec.add_development_dependency 'rspec-rails', '~> 3.0'
|
33
|
-
spec.add_development_dependency '
|
34
|
+
spec.add_development_dependency 'sqlite3', '>= 1.4'
|
34
35
|
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
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.5'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: actionpack
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,30 +143,30 @@ dependencies:
|
|
129
143
|
- !ruby/object:Gem::Version
|
130
144
|
version: '3.0'
|
131
145
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
146
|
+
name: sqlite3
|
133
147
|
requirement: !ruby/object:Gem::Requirement
|
134
148
|
requirements:
|
135
|
-
- - "
|
149
|
+
- - ">="
|
136
150
|
- !ruby/object:Gem::Version
|
137
|
-
version: '1.
|
151
|
+
version: '1.4'
|
138
152
|
type: :development
|
139
153
|
prerelease: false
|
140
154
|
version_requirements: !ruby/object:Gem::Requirement
|
141
155
|
requirements:
|
142
|
-
- - "
|
156
|
+
- - ">="
|
143
157
|
- !ruby/object:Gem::Version
|
144
|
-
version: '1.
|
145
|
-
description:
|
158
|
+
version: '1.4'
|
159
|
+
description:
|
146
160
|
email:
|
147
|
-
- benedikt@userlist.
|
161
|
+
- benedikt@userlist.com
|
148
162
|
executables: []
|
149
163
|
extensions: []
|
150
164
|
extra_rdoc_files: []
|
151
165
|
files:
|
166
|
+
- ".github/workflows/test.yml"
|
152
167
|
- ".gitignore"
|
153
168
|
- ".rspec"
|
154
169
|
- ".rubocop.yml"
|
155
|
-
- ".travis.yml"
|
156
170
|
- CODE_OF_CONDUCT.md
|
157
171
|
- Gemfile
|
158
172
|
- Guardfile
|
@@ -162,24 +176,29 @@ files:
|
|
162
176
|
- bin/console
|
163
177
|
- bin/setup
|
164
178
|
- bin/test
|
165
|
-
- lib/tasks/userlist.rake
|
166
179
|
- lib/userlist/rails.rb
|
167
|
-
- lib/userlist/rails/company.rb
|
168
180
|
- lib/userlist/rails/config.rb
|
181
|
+
- lib/userlist/rails/extensions/company.rb
|
169
182
|
- lib/userlist/rails/extensions/event.rb
|
170
|
-
- lib/userlist/rails/extensions/
|
183
|
+
- lib/userlist/rails/extensions/relationship.rb
|
184
|
+
- lib/userlist/rails/extensions/user.rb
|
171
185
|
- lib/userlist/rails/helpers.rb
|
172
186
|
- lib/userlist/rails/importer.rb
|
173
187
|
- lib/userlist/rails/logger.rb
|
174
188
|
- lib/userlist/rails/railtie.rb
|
175
|
-
- lib/userlist/rails/
|
189
|
+
- lib/userlist/rails/tasks/userlist.rake
|
190
|
+
- lib/userlist/rails/transform.rb
|
191
|
+
- lib/userlist/rails/transforms/company.rb
|
192
|
+
- lib/userlist/rails/transforms/has_relationships.rb
|
193
|
+
- lib/userlist/rails/transforms/relationship.rb
|
194
|
+
- lib/userlist/rails/transforms/user.rb
|
176
195
|
- lib/userlist/rails/version.rb
|
177
196
|
- userlist-rails.gemspec
|
178
197
|
homepage: https://github.com/userlistio/userlist-rails
|
179
198
|
licenses:
|
180
199
|
- MIT
|
181
200
|
metadata: {}
|
182
|
-
post_install_message:
|
201
|
+
post_install_message:
|
183
202
|
rdoc_options: []
|
184
203
|
require_paths:
|
185
204
|
- lib
|
@@ -187,15 +206,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
206
|
requirements:
|
188
207
|
- - ">="
|
189
208
|
- !ruby/object:Gem::Version
|
190
|
-
version: '2.
|
209
|
+
version: '2.4'
|
191
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
211
|
requirements:
|
193
212
|
- - ">="
|
194
213
|
- !ruby/object:Gem::Version
|
195
214
|
version: '0'
|
196
215
|
requirements: []
|
197
|
-
rubygems_version: 3.
|
198
|
-
signing_key:
|
216
|
+
rubygems_version: 3.1.4
|
217
|
+
signing_key:
|
199
218
|
specification_version: 4
|
200
|
-
summary: Rails integration for Userlist
|
219
|
+
summary: Rails integration for Userlist
|
201
220
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
require 'userlist/push'
|
3
|
-
|
4
|
-
module Userlist
|
5
|
-
module Rails
|
6
|
-
module Company
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
if method = [:after_commit, :after_save].find { |m| respond_to?(m) }
|
11
|
-
public_send(method, :userlist_push, on: [:create, :update])
|
12
|
-
public_send(method, :userlist_delete, on: [:destroy])
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def userlist_identifier
|
17
|
-
"#{self.class.name}-#{id}".parameterize
|
18
|
-
end
|
19
|
-
|
20
|
-
def userlist_properties
|
21
|
-
{}
|
22
|
-
end
|
23
|
-
|
24
|
-
def userlist_payload
|
25
|
-
{
|
26
|
-
identifier: userlist_identifier,
|
27
|
-
name: userlist_name,
|
28
|
-
properties: userlist_properties
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def userlist_name
|
33
|
-
return name if respond_to?(:name)
|
34
|
-
end
|
35
|
-
|
36
|
-
def userlist_push
|
37
|
-
Userlist::Push.companies.push(userlist_payload)
|
38
|
-
end
|
39
|
-
|
40
|
-
def userlist_delete
|
41
|
-
Userlist::Push.companies.delete(userlist_identifier)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/transform_values' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0')
|
2
|
-
|
3
|
-
module Userlist
|
4
|
-
module Rails
|
5
|
-
module Extensions
|
6
|
-
module Resource
|
7
|
-
def initialize(payload = {})
|
8
|
-
super(transform_payload(payload))
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def transform_payload(payload)
|
14
|
-
payload = transform_value(payload)
|
15
|
-
|
16
|
-
return payload unless payload.is_a?(Hash)
|
17
|
-
|
18
|
-
payload.transform_values do |value|
|
19
|
-
result = transform_value(value)
|
20
|
-
result = transform_payload(result) if result.is_a?(Hash)
|
21
|
-
result
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def transform_value(value)
|
26
|
-
if value.respond_to?(:userlist_payload)
|
27
|
-
value.send(:userlist_payload)
|
28
|
-
else
|
29
|
-
value
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/userlist/rails/user.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
require 'userlist/push'
|
3
|
-
|
4
|
-
module Userlist
|
5
|
-
module Rails
|
6
|
-
module User
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
if method = [:after_commit, :after_save].find { |m| respond_to?(m) }
|
11
|
-
public_send(method, :userlist_push, on: [:create, :update])
|
12
|
-
public_send(method, :userlist_delete, on: [:destroy])
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def userlist_identifier
|
17
|
-
"#{self.class.name}-#{id}".parameterize
|
18
|
-
end
|
19
|
-
|
20
|
-
def userlist_properties
|
21
|
-
{}
|
22
|
-
end
|
23
|
-
|
24
|
-
def userlist_email
|
25
|
-
return email if respond_to?(:email)
|
26
|
-
end
|
27
|
-
|
28
|
-
def userlist_company
|
29
|
-
nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def userlist_payload
|
33
|
-
{
|
34
|
-
identifier: userlist_identifier,
|
35
|
-
email: userlist_email,
|
36
|
-
company: userlist_company,
|
37
|
-
properties: userlist_properties,
|
38
|
-
signed_up_at: created_at
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
def userlist_push
|
43
|
-
Userlist::Push.users.push(userlist_payload)
|
44
|
-
end
|
45
|
-
|
46
|
-
def userlist_delete
|
47
|
-
Userlist::Push.users.delete(userlist_identifier)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|