api_client_bulk_loader 0.1.10 → 0.1.11
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/lib/api_client_bulk_loader/api_client_bulk_loader.rb +1 -0
- data/lib/api_client_bulk_loader/client/association_adapter.rb +3 -12
- data/lib/api_client_bulk_loader/client/association_helper.rb +1 -1
- data/lib/api_client_bulk_loader/client/bulk_load_adapter.rb +29 -0
- data/lib/api_client_bulk_loader/client/bulk_load_helper.rb +2 -0
- data/lib/api_client_bulk_loader/client/loader.rb +1 -1
- data/lib/api_client_bulk_loader/client/polymorphic_association_adapter.rb +5 -14
- data/lib/api_client_bulk_loader/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe9cc6ce883ae5a1ef9158539058ebed422ab9d4
|
4
|
+
data.tar.gz: 5164ee12c815c6edfb379b6d6dc0754e86d19c3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dda0f8cf03dfa336336eba9a9c89767aa50919a7dd4312c6a133e8817bccf886989beb7bd6a3249e3eda21eb6e66b532b605731f4309353f0cd47d6e3794f0b
|
7
|
+
data.tar.gz: 3d14cf32d5248947288e1f496e4d54e12d98a3f1ad02764d4253ece6e21729db7a4a79eec678234abab56bad73c51b40ef38b3f5c9011c53725ea2992e2d163e
|
@@ -6,6 +6,7 @@ module ApiClientBulkLoader
|
|
6
6
|
autoload :AssociationAdapter, 'api_client_bulk_loader/client/association_adapter'
|
7
7
|
autoload :PolymorphicAssociationHelper, 'api_client_bulk_loader/client/polymorphic_association_helper'
|
8
8
|
autoload :PolymorphicAssociationAdapter, 'api_client_bulk_loader/client/polymorphic_association_adapter'
|
9
|
+
autoload :BulkLoadAdapter, 'api_client_bulk_loader/client/bulk_load_adapter'
|
9
10
|
autoload :BulkLoadHelper, 'api_client_bulk_loader/client/bulk_load_helper'
|
10
11
|
autoload :Loader, 'api_client_bulk_loader/client/loader'
|
11
12
|
end
|
@@ -1,21 +1,12 @@
|
|
1
1
|
module ApiClientBulkLoader
|
2
2
|
module Client
|
3
3
|
#Adapts into the bulk loader. Mainly useful for storing the details of the bulk call.
|
4
|
-
class AssociationAdapter
|
5
|
-
attr_reader :resource_model
|
4
|
+
class AssociationAdapter < BulkLoadAdapter
|
5
|
+
attr_reader :resource_model
|
6
6
|
|
7
7
|
def initialize(res_model, attribute = nil, values_from = nil, autoload = false, is_has_one = false, limit = nil)
|
8
8
|
@resource_model = res_model
|
9
|
-
|
10
|
-
@autoload = autoload
|
11
|
-
@values_from = values_from
|
12
|
-
@has_one = is_has_one
|
13
|
-
@limit = limit
|
14
|
-
end
|
15
|
-
|
16
|
-
def bulk_loader
|
17
|
-
RequestStore.store[:bulk_loader] ||= ApiClientBulkLoader::Client::Loader.new
|
18
|
-
return RequestStore.store[:bulk_loader]
|
9
|
+
super(attribute, values_from, autoload, is_has_one, limit)
|
19
10
|
end
|
20
11
|
|
21
12
|
#Fetch.
|
@@ -38,7 +38,7 @@ module ApiClientBulkLoader
|
|
38
38
|
adapter = self.class.bulk_queued_associations[association]
|
39
39
|
#Probably just raise an exception if it doesnt respond to the target.
|
40
40
|
values = Array(self.send(adapter.values_from))
|
41
|
-
limit
|
41
|
+
limit ||= adapter.limit
|
42
42
|
|
43
43
|
values = values.first(limit) if limit.present?
|
44
44
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ApiClientBulkLoader
|
2
|
+
module Client
|
3
|
+
#Adapts into the bulk loader. Mainly useful for storing the details of the bulk call.
|
4
|
+
class BulkLoadAdapter
|
5
|
+
attr_reader :attribute, :autoload, :values_from, :limit
|
6
|
+
|
7
|
+
def initialize(attribute = nil, values_from = nil, autoload = false, is_has_one = false, limit = nil)
|
8
|
+
@attribute = attribute
|
9
|
+
@autoload = autoload
|
10
|
+
@values_from = values_from || "#{attribute}_id"
|
11
|
+
@has_one = is_has_one
|
12
|
+
@limit = limit
|
13
|
+
end
|
14
|
+
|
15
|
+
def bulk_loader
|
16
|
+
RequestStore.store[:bulk_loader] ||= ApiClientBulkLoader::Client::Loader.new
|
17
|
+
return RequestStore.store[:bulk_loader]
|
18
|
+
end
|
19
|
+
|
20
|
+
def push
|
21
|
+
raise Exception.new("Child class should define push!")
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch
|
25
|
+
raise Exception.new("Child class should define fetch!")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -30,6 +30,8 @@ module ApiClientBulkLoader
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
#we need to override this, as if it is called before we actually hit a bulk-loaded assocation, it will attempt to JSON serialize a proc, which isn't good.
|
34
|
+
#To remedy this, we forcefully call each attribute and if it's a proc, we fire that bulk fetch.
|
33
35
|
def as_json(options=nil)
|
34
36
|
prepare_attributes_hash
|
35
37
|
super(options)
|
@@ -50,7 +50,7 @@ module ApiClientBulkLoader
|
|
50
50
|
|
51
51
|
values = @queued_model_store[model][attribute]
|
52
52
|
|
53
|
-
results = if attribute != :id #Index the returned results by the attribute used to query by
|
53
|
+
results = if attribute != :id #Index the returned results by the attribute used to query by, this is used when bulk querying by some foreign key.
|
54
54
|
|
55
55
|
Array(model.find(attribute => values)).group_by{|obj| obj.send(attribute) }
|
56
56
|
|
@@ -1,24 +1,15 @@
|
|
1
1
|
module ApiClientBulkLoader
|
2
2
|
module Client
|
3
3
|
#Adapts into the bulk loader. Mainly useful for storing the details of the bulk call.
|
4
|
-
class PolymorphicAssociationAdapter
|
5
|
-
attr_reader :resource_translation, :
|
4
|
+
class PolymorphicAssociationAdapter < BulkLoadAdapter
|
5
|
+
attr_reader :resource_translation, :type_from
|
6
6
|
|
7
|
-
def initialize(resource_translation, attribute = nil, type_from = nil, values_from = nil, autoload =
|
7
|
+
def initialize(resource_translation, attribute = nil, type_from = nil, values_from = nil, autoload = true, is_has_one = false, limit = nil)
|
8
8
|
@resource_translation = resource_translation
|
9
|
-
@attribute = attribute
|
10
|
-
@autoload = autoload
|
11
|
-
@values_from = values_from
|
12
9
|
@type_from = type_from
|
13
|
-
|
14
|
-
@limit = limit
|
10
|
+
super(attribute, values_from, autoload, is_has_one, limit)
|
15
11
|
end
|
16
|
-
|
17
|
-
def bulk_loader
|
18
|
-
RequestStore.store[:bulk_loader] ||= ApiClientBulkLoader::Client::Loader.new
|
19
|
-
return RequestStore.store[:bulk_loader]
|
20
|
-
end
|
21
|
-
|
12
|
+
|
22
13
|
#Fetch.
|
23
14
|
def fetch(values, resource_type)
|
24
15
|
results = bulk_loader.fetch(@resource_translation[resource_type], values, @attribute)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client_bulk_loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alex
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/api_client_bulk_loader/api_client_bulk_loader.rb
|
79
79
|
- lib/api_client_bulk_loader/client/association_adapter.rb
|
80
80
|
- lib/api_client_bulk_loader/client/association_helper.rb
|
81
|
+
- lib/api_client_bulk_loader/client/bulk_load_adapter.rb
|
81
82
|
- lib/api_client_bulk_loader/client/bulk_load_helper.rb
|
82
83
|
- lib/api_client_bulk_loader/client/loader.rb
|
83
84
|
- lib/api_client_bulk_loader/client/polymorphic_association_adapter.rb
|