the_grid 1.1.1 → 1.1.2
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 +7 -3
- data/lib/the_grid/builder.rb +1 -1
- data/lib/the_grid/version.rb +1 -1
- data/spec/builder/csv_spec.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmUzMzViNTAwMmM5MjlmNGVjOWY2OGY1N2E3ZmVhMzBiYTA5NDhlOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWY0N2ZlYzE4N2U1ZWUwMjhkOTJjNWUzNjE3OTY0ZDY4ODlkNTNkOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWU3NzRhMGNjM2ZiMzQwMGVjMTAyNTdhMTQyZDE2MDM3YzQ1ZjNhODhhZDc5
|
10
|
+
ZGZiZDdmNGM1ZmRlMDY5ZjU1M2U1ZDdkZjE2MTQ5YjZmMjc3MDE2MGJiYmRk
|
11
|
+
N2ZmOGVhN2YwODZjOTFiNDBiOTNiYmRjNTIwMTBmNzQ4NmJjYWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmE5ZDRkODVjMjMxMzI1MDRkNDQzMzkwYjU4MTZlZWIxMWFjYTBiMjAxYzRh
|
14
|
+
ODgxZmU3ZmJlOGMxZWI3ZjE5ODc5MDJhMzY5ZGIxNDU0MTAxZDE5Nzk5ZDVm
|
15
|
+
ZDdjYmMzNmI5NDY1MzJmMzQ5MDU5MTk2Zjg4ZWRjOTUwZDVjOTU=
|
data/lib/the_grid/builder/csv.rb
CHANGED
@@ -13,7 +13,7 @@ module TheGrid
|
|
13
13
|
|
14
14
|
def assemble_with(params)
|
15
15
|
options = params.merge context.params
|
16
|
-
api.compose!(options.merge :per_page => BATCH_SIZE)
|
16
|
+
api.compose!(options.merge :per_page => BATCH_SIZE) if api.relation.respond_to?(:except)
|
17
17
|
generate_csv_with(options)
|
18
18
|
end
|
19
19
|
|
@@ -22,9 +22,13 @@ module TheGrid
|
|
22
22
|
def generate_csv_with(options)
|
23
23
|
CSV.generate do |csv|
|
24
24
|
csv << headers
|
25
|
-
put_relation_to(csv)
|
25
|
+
api.relation.kind_of?(Array) ? put_data_to(csv) : put_relation_to(csv)
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
def put_data_to(csv)
|
30
|
+
put_records_to(csv, api.relation)
|
31
|
+
end
|
28
32
|
|
29
33
|
def put_relation_to(csv)
|
30
34
|
(1..api.options[:max_page]).each do |page|
|
@@ -38,7 +42,7 @@ module TheGrid
|
|
38
42
|
end
|
39
43
|
|
40
44
|
def headers
|
41
|
-
context.options[:
|
45
|
+
context.options[:titles] || context.columns.keys.map { |col| col.to_s.titleize }
|
42
46
|
end
|
43
47
|
|
44
48
|
end
|
data/lib/the_grid/builder.rb
CHANGED
@@ -37,7 +37,7 @@ module TheGrid
|
|
37
37
|
|
38
38
|
def grid_for(relation, options = {}, &block)
|
39
39
|
context = Context.new(options.merge(:scope => @_scope), &block)
|
40
|
-
@_view_type.new(relation, context)
|
40
|
+
@_view_type.new(relation, context).assemble_with(@_scope.params)
|
41
41
|
end
|
42
42
|
|
43
43
|
def method_missing(name, *args, &block)
|
data/lib/the_grid/version.rb
CHANGED
data/spec/builder/csv_spec.rb
CHANGED
@@ -13,13 +13,13 @@ describe TheGrid::Builder::Csv do
|
|
13
13
|
let(:params) {{ :cmd => [:sort], :field => :name, :order => :desc, :per_page => subject.class.const_get("BATCH_SIZE") }}
|
14
14
|
|
15
15
|
it "generates expected csv string" do
|
16
|
-
subject.assemble_with(params).should eql generate_csv(records, subject.context.options[:
|
16
|
+
subject.assemble_with(params).should eql generate_csv(records, subject.context.options[:titles])
|
17
17
|
end
|
18
18
|
|
19
|
-
it "uses titleized column names if
|
19
|
+
it "uses titleized column names if titles are not specified" do
|
20
20
|
subject.context.stub(:options => {})
|
21
|
-
|
22
|
-
subject.assemble_with(params).should eql generate_csv(records,
|
21
|
+
titles = record.keys.map{|c| c.to_s.titleize }
|
22
|
+
subject.assemble_with(params).should eql generate_csv(records, titles)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "generates csv records in batches" do
|
@@ -28,16 +28,16 @@ describe TheGrid::Builder::Csv do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
|
31
|
-
def generate_csv(records,
|
31
|
+
def generate_csv(records, titles)
|
32
32
|
CSV.generate do |csv|
|
33
|
-
csv <<
|
33
|
+
csv << titles
|
34
34
|
records.each{ |item| csv << item.values }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def build_context
|
39
39
|
TheGrid::Builder::Context.new do
|
40
|
-
|
40
|
+
titles "Id", "Title", "Status", "Description"
|
41
41
|
column :name
|
42
42
|
column :status
|
43
43
|
column :text
|
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.2
|
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-
|
12
|
+
date: 2013-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|