api_client_bulk_loader 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_client_bulk_loader/client/association_helper.rb +2 -4
- data/lib/api_client_bulk_loader/client/bulk_load_helper.rb +36 -12
- data/lib/api_client_bulk_loader/client/polymorphic_association_helper.rb +2 -4
- data/lib/api_client_bulk_loader/version.rb +1 -1
- data/test/test_helper.rb +0 -8
- metadata +2 -18
- data/test/dummy/app/controllers/variant_objects_controller.rb +0 -10
- data/test/dummy/app/models/variant_object.rb +0 -2
- data/test/dummy/app/views/variant_objects/_variant_object.html.erb +0 -1
- data/test/dummy/app/views/variant_objects/_variant_object_medium.html.erb +0 -1
- data/test/dummy/app/views/variant_objects/_variant_object_small.html.erb +0 -1
- data/test/dummy/app/views/variant_objects/index.html.erb +0 -24
- data/test/dummy/test/fixtures/variant_objects.yml +0 -14
- data/test/integration/variant_object_controller_test.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e249c8aea7f0eccdca7a4b2b441168a3ffa3904a
|
4
|
+
data.tar.gz: 44c3bed52a08f7e701e25953eaf0226fa1c08df9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0343efed332cda6989fa59a5e0fead211d1c15ceaafe558c0a648754f23580d924288ad77e0ca93faab7a9c82eacd583c4060be932d07e606bc56cb4c49a687
|
7
|
+
data.tar.gz: 0514541ac5680eaa55cec183da5850384a4592d24feb36711955cd9e2cf7f07cb4c55218a271d8f710f603119b7869ec717e522e0cb30e12dc5d64616b920b5c
|
@@ -27,8 +27,6 @@ module ApiClientBulkLoader
|
|
27
27
|
def self.bulk_load(association, api_client_model, attribute: :id, autoload: false, from: :id, is_has_one: false, limit: nil)
|
28
28
|
@bulk_queued_associations ||= {}
|
29
29
|
@bulk_queued_associations[association] = ApiClientBulkLoader::Client::AssociationAdapter.new(api_client_model, attribute, from, autoload, is_has_one, limit)
|
30
|
-
|
31
|
-
define_bulk_method(association)
|
32
30
|
end
|
33
31
|
|
34
32
|
#Shorthand to the above, but automatically sets 'is_has_one' to true.
|
@@ -47,9 +45,9 @@ module ApiClientBulkLoader
|
|
47
45
|
|
48
46
|
if !values.nil?
|
49
47
|
adapter.push(values)
|
50
|
-
|
48
|
+
attributes[association] = ->{
|
51
49
|
adapter.fetch(values)
|
52
|
-
}
|
50
|
+
}
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
@@ -14,18 +14,6 @@ module ApiClientBulkLoader
|
|
14
14
|
@bulk_queued_associations
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.define_bulk_method(association)
|
18
|
-
#define new getter for assoc that uses the proc
|
19
|
-
define_method association.to_s do
|
20
|
-
ivar = self.instance_variable_get("@#{association}")
|
21
|
-
if (ivar.is_a? Proc)
|
22
|
-
self.instance_variable_set("@#{association}", ivar.call)
|
23
|
-
else
|
24
|
-
ivar
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
17
|
def initialize(*args)
|
30
18
|
super(*args)
|
31
19
|
#Skip em unless we got em
|
@@ -41,6 +29,42 @@ module ApiClientBulkLoader
|
|
41
29
|
return self
|
42
30
|
end
|
43
31
|
end
|
32
|
+
|
33
|
+
def as_json(options=nil)
|
34
|
+
prepare_attributes_hash
|
35
|
+
super(options)
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def method_missing(method, *args, &block)
|
41
|
+
if method.to_s =~ /^(.*)=$/
|
42
|
+
set_attribute($1, args.first)
|
43
|
+
elsif has_attribute?(method)
|
44
|
+
read_attribute(method)
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def read_attribute(name)
|
51
|
+
value = attributes.fetch(name, nil)
|
52
|
+
if(value.is_a? Proc)
|
53
|
+
attributes[name] = attributes[name].call
|
54
|
+
value = attributes[name]
|
55
|
+
end
|
56
|
+
|
57
|
+
return value
|
58
|
+
end
|
59
|
+
|
60
|
+
def prepare_attributes_hash
|
61
|
+
return unless self.class.bulk_queued_associations.present?
|
62
|
+
self.class.bulk_queued_associations.keys.each do |assoc|
|
63
|
+
if(attributes[assoc].is_a? Proc)
|
64
|
+
attributes[assoc] = attributes[assoc].call
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
44
68
|
end
|
45
69
|
end
|
46
70
|
end
|
@@ -30,8 +30,6 @@ module ApiClientBulkLoader
|
|
30
30
|
def self.bulk_load_poly(association, type_model_hash, attribute: :id, autoload: false, type_from: :document_type, from: :document_id, is_has_one: false, limit: nil)
|
31
31
|
@bulk_queued_associations ||= {}
|
32
32
|
@bulk_queued_associations[association] = ApiClientBulkLoader::Client::PolymorphicAssociationAdapter.new(type_model_hash, attribute,type_from, from, autoload, is_has_one, limit)
|
33
|
-
|
34
|
-
define_bulk_method(association)
|
35
33
|
end
|
36
34
|
|
37
35
|
def self.bulk_load_poly_has_one(*args, **kwargs)
|
@@ -50,9 +48,9 @@ module ApiClientBulkLoader
|
|
50
48
|
|
51
49
|
if !values.nil?
|
52
50
|
adapter.push(values, resource_type)
|
53
|
-
|
51
|
+
attributes[association] = ->{
|
54
52
|
adapter.fetch(values, resource_type)
|
55
|
-
}
|
53
|
+
}
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
data/test/test_helper.rb
CHANGED
@@ -16,11 +16,3 @@ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
|
16
16
|
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
17
17
|
end
|
18
18
|
|
19
|
-
def variants_for_test
|
20
|
-
[:medium, :small]
|
21
|
-
end
|
22
|
-
|
23
|
-
#How many time we should expect to see the item rendered in index.
|
24
|
-
def expected_render_count
|
25
|
-
VariantObject.count * 3
|
26
|
-
end
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alex
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -74,14 +74,8 @@ files:
|
|
74
74
|
- test/dummy/app/assets/javascripts/application.js
|
75
75
|
- test/dummy/app/assets/stylesheets/application.css
|
76
76
|
- test/dummy/app/controllers/application_controller.rb
|
77
|
-
- test/dummy/app/controllers/variant_objects_controller.rb
|
78
77
|
- test/dummy/app/helpers/application_helper.rb
|
79
|
-
- test/dummy/app/models/variant_object.rb
|
80
78
|
- test/dummy/app/views/layouts/application.html.erb
|
81
|
-
- test/dummy/app/views/variant_objects/_variant_object.html.erb
|
82
|
-
- test/dummy/app/views/variant_objects/_variant_object_medium.html.erb
|
83
|
-
- test/dummy/app/views/variant_objects/_variant_object_small.html.erb
|
84
|
-
- test/dummy/app/views/variant_objects/index.html.erb
|
85
79
|
- test/dummy/bin/bundle
|
86
80
|
- test/dummy/bin/rails
|
87
81
|
- test/dummy/bin/rake
|
@@ -112,8 +106,6 @@ files:
|
|
112
106
|
- test/dummy/public/422.html
|
113
107
|
- test/dummy/public/500.html
|
114
108
|
- test/dummy/public/favicon.ico
|
115
|
-
- test/dummy/test/fixtures/variant_objects.yml
|
116
|
-
- test/integration/variant_object_controller_test.rb
|
117
109
|
- test/test_helper.rb
|
118
110
|
homepage: http://github.com/alexanderross/api_client_bulk_loader
|
119
111
|
licenses: []
|
@@ -142,14 +134,8 @@ test_files:
|
|
142
134
|
- test/dummy/app/assets/javascripts/application.js
|
143
135
|
- test/dummy/app/assets/stylesheets/application.css
|
144
136
|
- test/dummy/app/controllers/application_controller.rb
|
145
|
-
- test/dummy/app/controllers/variant_objects_controller.rb
|
146
137
|
- test/dummy/app/helpers/application_helper.rb
|
147
|
-
- test/dummy/app/models/variant_object.rb
|
148
138
|
- test/dummy/app/views/layouts/application.html.erb
|
149
|
-
- test/dummy/app/views/variant_objects/_variant_object.html.erb
|
150
|
-
- test/dummy/app/views/variant_objects/_variant_object_medium.html.erb
|
151
|
-
- test/dummy/app/views/variant_objects/_variant_object_small.html.erb
|
152
|
-
- test/dummy/app/views/variant_objects/index.html.erb
|
153
139
|
- test/dummy/bin/bundle
|
154
140
|
- test/dummy/bin/rails
|
155
141
|
- test/dummy/bin/rake
|
@@ -182,7 +168,5 @@ test_files:
|
|
182
168
|
- test/dummy/public/favicon.ico
|
183
169
|
- test/dummy/Rakefile
|
184
170
|
- test/dummy/README.rdoc
|
185
|
-
- test/dummy/test/fixtures/variant_objects.yml
|
186
|
-
- test/integration/variant_object_controller_test.rb
|
187
171
|
- test/test_helper.rb
|
188
172
|
has_rdoc:
|
@@ -1 +0,0 @@
|
|
1
|
-
<h1 class="default_template"><%= variant_object.name %></h1>
|
@@ -1 +0,0 @@
|
|
1
|
-
<h2 class="medium_template"><%= variant_object.name %></h2>
|
@@ -1 +0,0 @@
|
|
1
|
-
<h3 class="small_template"><%= variant_object.name %></h3>
|
@@ -1,24 +0,0 @@
|
|
1
|
-
<div id="test_disp_container">
|
2
|
-
<% if @variant %>
|
3
|
-
|
4
|
-
<%= render @variant_objects, :variant => @variant %>
|
5
|
-
<hr/>
|
6
|
-
<% @variant_objects.each do |variant_object| %>
|
7
|
-
<%= render :partial=> variant_object, :variant => @variant %>
|
8
|
-
<br/>
|
9
|
-
<%= render variant_object, :variant => @variant %>
|
10
|
-
<% end %>
|
11
|
-
|
12
|
-
<% else %>
|
13
|
-
<%= render @variant_objects %>
|
14
|
-
<hr/>
|
15
|
-
<% @variant_objects.each do |variant_object| %>
|
16
|
-
<%= render :partial=> variant_object %>
|
17
|
-
<br/>
|
18
|
-
<%= render variant_object %>
|
19
|
-
<% end %>
|
20
|
-
<% end %>
|
21
|
-
<% if params[:test_nil_path] %>
|
22
|
-
<%= render %>
|
23
|
-
<% end %>
|
24
|
-
</div>
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
2
|
-
|
3
|
-
# This model initially had no columns defined. If you add columns to the
|
4
|
-
# model remove the '{}' from the fixture names and add the columns immediately
|
5
|
-
# below each fixture, per the syntax in the comments below
|
6
|
-
#
|
7
|
-
one:
|
8
|
-
name: "Test1"
|
9
|
-
desc: "test1 description"
|
10
|
-
# column: value
|
11
|
-
#
|
12
|
-
two:
|
13
|
-
name: "Test2"
|
14
|
-
desc: "test2 description"
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class VariantObjectControllerTest < ActionDispatch::IntegrationTest
|
4
|
-
fixtures :all
|
5
|
-
|
6
|
-
#instead of loading individual partials, attempt to render the entire collection with and without variants
|
7
|
-
test "renders without variant" do
|
8
|
-
get variant_objects_path
|
9
|
-
assert_response :success
|
10
|
-
assert_select ".default_template", :count=> expected_render_count
|
11
|
-
end
|
12
|
-
|
13
|
-
test "renders with variant" do
|
14
|
-
variants_for_test.each do |name|
|
15
|
-
get variant_objects_path(:variant => name)
|
16
|
-
assert_response :success
|
17
|
-
assert_select ".#{name}_template", :count=> expected_render_count
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
test 'doesnt break with nil path' do
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|