the_grid 1.1.4 → 1.1.5
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 +8 -8
- data/lib/the_grid/builder/csv.rb +6 -6
- data/lib/the_grid/version.rb +1 -1
- data/spec/builder/csv_spec.rb +7 -0
- data/spec/builder/view_builder_helper.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Yzg5ZTNhZWI2OTc2ZWFjMjk3NzNlZTRhMzA0NTQzMTFlYzBhOTFlMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDM0ZWEwMWMzZGEwNzllNDY5YmY0ZDVmMmZhYjBlYmJjZGEyMGUyNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODc4YjY5NzNmNmZlOGEwM2ZjZDBmNTVlYmY3MDJiODY0ODFjOTIyMjYxMzYw
|
10
|
+
NTExZGZlYjQzMWZiMDUzOGEwZjI5MWE3YmQwMjNmYWU1YmM0ZjJiYjYyNWFh
|
11
|
+
MTZkZTdjOTYzZTEyNTZhNjIzYmI2OTA5NTBmNDVmYjJjNTExYTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTgwODM3MzZhMDhmNWNiYTQ0OTU4MjhkMjAxOGViMjYxOGE2NGI0ODhkZTU4
|
14
|
+
N2M5ODJlMWVmZGNkMjE3NzllNDRhMTRlMmJmYjc5MzNmYTE4YTRhYWI1ZmZl
|
15
|
+
MDlkNjg5ZjRiMDExNjFhNThjYTgxZGVjMjczYTMxYzM1NjljMTI=
|
data/lib/the_grid/builder/csv.rb
CHANGED
@@ -7,11 +7,11 @@ module TheGrid
|
|
7
7
|
|
8
8
|
def build(context, options)
|
9
9
|
records, params = options.values_at(:for, :with)
|
10
|
-
|
11
|
-
api = compose(records,
|
10
|
+
params.merge!(:per_page => records.kind_of?(Array) ? false : BATCH_SIZE)
|
11
|
+
api = compose(records, params)
|
12
12
|
CSV.generate do |csv|
|
13
13
|
csv << context.column_titles
|
14
|
-
|
14
|
+
params[:per_page] ? put(context, :to => csv, :with => api) : put_this(context, :to => csv, :with => records)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -21,8 +21,8 @@ module TheGrid
|
|
21
21
|
api, csv = options.values_at(:with, :to)
|
22
22
|
pages = api.options[:max_page]
|
23
23
|
(1..pages).each do |page|
|
24
|
-
|
25
|
-
put_this(context,
|
24
|
+
options[:with] = api.run_command!(:paginate, :page => page, :per_page => BATCH_SIZE, :size => pages * BATCH_SIZE)
|
25
|
+
put_this(context, options)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -39,7 +39,7 @@ module TheGrid
|
|
39
39
|
if value.kind_of?(Array)
|
40
40
|
row_nested_values += value.flat_map{ |r| flatten(r) }
|
41
41
|
else
|
42
|
-
row_values << value
|
42
|
+
row_values << value
|
43
43
|
end
|
44
44
|
end
|
45
45
|
return [ row_values ] if row_nested_values.empty?
|
data/lib/the_grid/version.rb
CHANGED
data/spec/builder/csv_spec.rb
CHANGED
@@ -30,6 +30,13 @@ describe TheGrid::Builder::Csv do
|
|
30
30
|
subject.assemble(context, :on => relation, :with => params).should eql generate_csv(2.times.map{ |i| record.merge child_record(i + 1) }, context.column_titles)
|
31
31
|
end
|
32
32
|
|
33
|
+
it "generates csv for array" do
|
34
|
+
context = build_context
|
35
|
+
object = build_double(1, :name, :status, :text)
|
36
|
+
object.stub(:children => [])
|
37
|
+
subject.assemble(context, :on => [ object ], :with => params).should eql generate_csv([ object ], context.column_titles)
|
38
|
+
end
|
39
|
+
|
33
40
|
|
34
41
|
def generate_csv(records, titles)
|
35
42
|
CSV.generate do |csv|
|
@@ -15,4 +15,13 @@ shared_examples "for Grid View Builder" do
|
|
15
15
|
def record(id = nil)
|
16
16
|
{ :id => id || 1, :name => "Name #{id}", :status => "Active", :text => "Text" }
|
17
17
|
end
|
18
|
+
|
19
|
+
def build_double(id, *methods)
|
20
|
+
impl = methods.each_with_object({ :id => id }) do |method, object|
|
21
|
+
object[method] = "#{method.to_s.titleize} #{id}"
|
22
|
+
end
|
23
|
+
impl[:values] = impl.values
|
24
|
+
double(impl)
|
25
|
+
end
|
26
|
+
|
18
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergiy Stotskiy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|