userlist 0.5.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/lib/userlist/push/company.rb +1 -1
- data/lib/userlist/push/relationship.rb +2 -1
- data/lib/userlist/push/resource.rb +11 -5
- data/lib/userlist/push/resource_collection.rb +14 -3
- data/lib/userlist/push/serializer.rb +2 -0
- data/lib/userlist/push/user.rb +1 -1
- data/lib/userlist/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f8e5ee8f9d8d18f98ebc7744ced642b9641ec6bd156fff4fbf0352be37dbaa2
|
4
|
+
data.tar.gz: a532a136941e347e7c7dc454f3ec7a735990f53abd8ddaff1bdf50eb67a3c219
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9065b7f9af8fc5692b334bcfa97410ee3260544f02cd6440cea57150d3daceb1e62c5b8fba8780f4309da764603966842b59064baad786918f1f23381a8ba0b5
|
7
|
+
data.tar.gz: f01918dafbaa9a837b25503f667b1387998036a5a626cce75fe3f45ef80539cb6e57aa9ab512bf8813f039b959eb138039ab0086bd98342dec5ef61f2d129969
|
@@ -8,7 +8,7 @@ module Userlist
|
|
8
8
|
'/companies'
|
9
9
|
end
|
10
10
|
|
11
|
-
has_many :relationships, type: 'Userlist::Push::Relationship'
|
11
|
+
has_many :relationships, type: 'Userlist::Push::Relationship', inverse: :company
|
12
12
|
has_many :users, type: 'Userlist::Push::User'
|
13
13
|
has_one :user, type: 'Userlist::Push::User'
|
14
14
|
|
@@ -9,7 +9,8 @@ module Userlist
|
|
9
9
|
|
10
10
|
def initialize(payload = {}, config = Userlist.config)
|
11
11
|
raise Userlist::ArgumentError, 'Missing required payload' unless payload
|
12
|
-
raise Userlist::ArgumentError, 'Missing required parameter :user
|
12
|
+
raise Userlist::ArgumentError, 'Missing required parameter :user' unless payload[:user]
|
13
|
+
raise Userlist::ArgumentError, 'Missing required parameter :company' unless payload[:company]
|
13
14
|
|
14
15
|
super
|
15
16
|
end
|
@@ -20,13 +20,17 @@ module Userlist
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def relationship_names
|
23
|
-
@relationship_names ||=
|
23
|
+
@relationship_names ||= relationships.keys
|
24
|
+
end
|
25
|
+
|
26
|
+
def relationships
|
27
|
+
@relationships ||= {}
|
24
28
|
end
|
25
29
|
|
26
30
|
protected
|
27
31
|
|
28
32
|
def has_one(name, type:) # rubocop:disable Naming/PredicateName
|
29
|
-
|
33
|
+
relationships[name.to_sym] = { type: type }
|
30
34
|
|
31
35
|
generated_methods.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
32
36
|
def #{name}
|
@@ -35,12 +39,14 @@ module Userlist
|
|
35
39
|
RUBY
|
36
40
|
end
|
37
41
|
|
38
|
-
def has_many(name,
|
39
|
-
|
42
|
+
def has_many(name, **options) # rubocop:disable Naming/PredicateName
|
43
|
+
relationships[name.to_sym] = options
|
40
44
|
|
41
45
|
generated_methods.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
42
46
|
def #{name}
|
43
|
-
|
47
|
+
relationship = self.class.relationships[:#{name}]
|
48
|
+
|
49
|
+
ResourceCollection.new(payload[:#{name}], relationship, self, config)
|
44
50
|
end
|
45
51
|
RUBY
|
46
52
|
end
|
@@ -3,19 +3,30 @@ module Userlist
|
|
3
3
|
class ResourceCollection
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
attr_reader :collection, :
|
6
|
+
attr_reader :collection, :relationship, :owner, :config
|
7
7
|
|
8
|
-
def initialize(collection,
|
8
|
+
def initialize(collection, relationship, owner, config = Userlist.config)
|
9
9
|
@collection = Array(collection)
|
10
|
-
@
|
10
|
+
@relationship = relationship
|
11
|
+
@owner = owner
|
11
12
|
@config = config
|
12
13
|
end
|
13
14
|
|
14
15
|
def each
|
15
16
|
collection.each do |resource|
|
17
|
+
resource[inverse] = owner if inverse && resource.is_a?(Hash)
|
18
|
+
|
16
19
|
yield type.from_payload(resource, config)
|
17
20
|
end
|
18
21
|
end
|
22
|
+
|
23
|
+
def type
|
24
|
+
Object.const_get(relationship[:type])
|
25
|
+
end
|
26
|
+
|
27
|
+
def inverse
|
28
|
+
relationship[:inverse]
|
29
|
+
end
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
data/lib/userlist/push/user.rb
CHANGED
@@ -4,7 +4,7 @@ module Userlist
|
|
4
4
|
include Operations::Create
|
5
5
|
include Operations::Delete
|
6
6
|
|
7
|
-
has_many :relationships, type: 'Userlist::Push::Relationship'
|
7
|
+
has_many :relationships, type: 'Userlist::Push::Relationship', inverse: :user
|
8
8
|
has_many :companies, type: 'Userlist::Push::Company'
|
9
9
|
has_one :company, type: 'Userlist::Push::Company'
|
10
10
|
|
data/lib/userlist/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: userlist
|
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: bundler
|