send_csv 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -3,6 +3,5 @@ History.txt
3
3
  Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
- bin/send_csv
7
6
  lib/send_csv.rb
8
7
  test/test_send_csv.rb
data/README.txt CHANGED
@@ -12,7 +12,7 @@ Adds to ApplicationController a send_csv method working like send_file.
12
12
  def export
13
13
  lines = []
14
14
  lines << ["Name", "e-mail"]
15
- lines += Users.all.map { |user| [user.name, user.email]
15
+ lines += User.all.map { |user| [user.name, user.email] }
16
16
  send_csv(lines, :filename => "exported_users.csv")
17
17
  end
18
18
  end
data/Rakefile CHANGED
@@ -13,4 +13,10 @@ Hoe.spec 'send_csv' do
13
13
  developer('Ouvrages', 'contact@ouvrages-web.fr')
14
14
  end
15
15
 
16
+ # http://blog.behindlogic.com/2008/10/auto-generate-your-manifest-and-gemspec.html
17
+ task :cultivate do
18
+ system "touch Manifest.txt; rake check_manifest | grep -v \"(in \" | patch"
19
+ system "rake debug_gem | grep -v \"(in \" > `basename \\`pwd\\``.gemspec"
20
+ end
21
+
16
22
  # vim: syntax=ruby
data/lib/send_csv.rb CHANGED
@@ -1,25 +1,36 @@
1
1
  module SendCsv
2
- VERSION = '0.2'
2
+ VERSION = '0.3'
3
3
  end
4
4
 
5
+ # Based on http://stackoverflow.com/questions/3468858/rails-3-0-engine-execute-code-in-actioncontroller/3484141#3484141
6
+
5
7
  require 'action_controller' # Make sure ActionController::Base is defined
6
8
 
7
9
  ActionController::Base.class_eval do
8
10
  private
9
11
 
10
- def send_csv(lines, options = {})
12
+ def generate_csv(lines, options = {})
11
13
  require 'csv'
12
14
 
13
15
  options = options.dup
14
16
  encoding = options.delete(:encoding) || 'ISO-8859-1'
15
17
 
18
+ csv = lines.map { |values| CSV.generate_line(values, ';') + "\r\n" }.join
19
+ csv = Iconv.conv(encoding, 'utf-8', csv)
20
+
21
+ csv
22
+ end
23
+
24
+ def send_csv(lines, options = {})
25
+ options = options.dup
26
+ encoding = options.delete(:encoding) || 'ISO-8859-1'
27
+
16
28
  options = {
17
29
  :disposition => "attachment",
18
30
  :type => 'text/plain',
19
31
  }.merge(options)
20
32
 
21
- csv = lines.map { |values| CSV.generate_line(values, ';') + "\r\n" }.join
22
- csv = Iconv.conv(encoding, 'utf-8', csv)
33
+ csv = generate_csv(lines, options)
23
34
 
24
35
  send_data csv, options
25
36
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: send_csv
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- version: "0.2"
8
+ - 3
9
+ version: "0.3"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ouvrages
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-05 00:00:00 +02:00
17
+ date: 2011-06-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -36,8 +36,8 @@ dependencies:
36
36
  description: Adds to ApplicationController a send_csv method working like send_file.
37
37
  email:
38
38
  - contact@ouvrages-web.fr
39
- executables:
40
- - send_csv
39
+ executables: []
40
+
41
41
  extensions: []
42
42
 
43
43
  extra_rdoc_files:
@@ -50,7 +50,6 @@ files:
50
50
  - Manifest.txt
51
51
  - README.txt
52
52
  - Rakefile
53
- - bin/send_csv
54
53
  - lib/send_csv.rb
55
54
  - test/test_send_csv.rb
56
55
  - .gemtest
data/bin/send_csv DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- abort "you need to write me"