collection2csv 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +8 -9
- data/app/controllers/collection2csv_controller.rb +17 -16
- data/lib/collection2csv/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OWE5ZDY5ZGVkN2NiZGMwNTI2ODI2NjI5M2VjMTI4OGQ2ZTIyNDRmNg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f527fb208082c9fd371fcc8f5c2147e866a2831
|
4
|
+
data.tar.gz: b8509cc8e931fce5ac80816ee02da06ddd268571
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MTNhZTEzYmExODM4NDU5OTM4YmJjMDgxNTBkMTM2NWRjNmQ4NzlhNzE3MDI2
|
11
|
-
YWI4NmU0YTY3ZGRmZmQzMDRmNzJlYTYwNzU0Mzg3ZDY0NTJlZTQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NWIzNDkzYTkwMzBlOTg1NzYwMTg2MmM1ZDc3ODBkNmI5MTkwMDZmNTJmNTFj
|
14
|
-
OGE3YTdmN2Y1ZmNmZTM4Y2NjOWEyOWZhYzU5NWQ0NmMzMWJiMDc2MDhjNzM3
|
15
|
-
OWNjOWMyOTgyOWIzZGQ5YTE4NmZlNDUxNzZkYTNlZTVkNmExZjk=
|
6
|
+
metadata.gz: c768071fb31f03eff502b2971a531f749e79259f8bc0541e6281a027c8a4374659f5160e3a37f167c08aeca57e43812d7cffa8b3f2fe1a35ddce2af970c934a4
|
7
|
+
data.tar.gz: 2a5f0bcf3cca073f282e82c505ea6ac9f5bb035cd66a155bfc7ef601944dad608d290b04a0d92380de6a2bb701b72c9d2fa2d9e3c08657e7f12677864e2cdd89
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Collection2csv
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Collection2csv gem allows you to export a collection of model objects to csv
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -14,7 +12,7 @@ gem 'collection2csv'
|
|
14
12
|
|
15
13
|
And then execute:
|
16
14
|
|
17
|
-
$ bundle
|
15
|
+
$ bundle install
|
18
16
|
|
19
17
|
Or install it yourself as:
|
20
18
|
|
@@ -22,17 +20,18 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
Use the collection_download helper like any other regular tag helper :
|
24
|
+
|
25
|
+
<%= collection_download(@collection) %>
|
26
26
|
|
27
|
-
|
27
|
+
In order to select a particular columns use column names as follows
|
28
28
|
|
29
|
-
|
29
|
+
<%= collection_download(@collection,'column_name1,column_name2') %>
|
30
30
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
31
|
|
33
32
|
## Contributing
|
34
33
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ethirajsrinivasan/collection2csv.
|
36
35
|
|
37
36
|
|
38
37
|
## License
|
@@ -4,21 +4,22 @@ class Collection2csvController < ApplicationController
|
|
4
4
|
klass = params[:klass].constantize
|
5
5
|
if params[:column_names].present?
|
6
6
|
column_names = params[:column_names].split(',').to_a
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
csv << product.attributes.values_at(*column_names)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
) ,:filename => "#{klass}_#{DateTime.now.to_formatted_s(:db)}"
|
7
|
+
else
|
8
|
+
column_names = klass.column_names
|
9
|
+
end
|
10
|
+
collection = klass.find(params[:ids])
|
11
|
+
respond_to do |format|
|
12
|
+
format.csv { send_data to_csv(collection,column_names) ,:filename => "#{klass}_#{DateTime.now.to_formatted_s(:db)}.csv"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def to_csv(collection,column_names)
|
18
|
+
CSV.generate do |csv|
|
19
|
+
csv << column_names.map(&:humanize)
|
20
|
+
collection.each do |product|
|
21
|
+
csv << product.attributes.values_at(*column_names)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
24
25
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collection2csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ethiraj
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
description: Download collection as csv
|
@@ -45,8 +45,8 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
49
|
-
- .travis.yml
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
50
|
- CODE_OF_CONDUCT.md
|
51
51
|
- Gemfile
|
52
52
|
- LICENSE.txt
|
@@ -71,12 +71,12 @@ require_paths:
|
|
71
71
|
- lib
|
72
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- -
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|