geetarista-export_csv 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +3 -3
  2. data/lib/export_csv.rb +3 -3
  3. metadata +1 -1
@@ -1,6 +1,6 @@
1
1
  == export_csv
2
2
 
3
- Very simple tool to export all records of an ActiveRecord model.
3
+ Very simple tool to export all records of an ActiveRecord model to a CSV file.
4
4
 
5
5
  == Examples
6
6
 
@@ -10,11 +10,11 @@ The only required parameter is the model name:
10
10
 
11
11
  The name of the generated file can be overriden by passing it with the :filename option:
12
12
 
13
- export_csv(User, :filename => "User Backup")
13
+ export_csv(User, :filename => "People")
14
14
 
15
15
  Find options for the model may also be passed with :parameters
16
16
 
17
- export_csv(User, :parameters => { :limit => 20 })
17
+ export_csv(User, :parameters => { :limit => 20, :order => "name asc" })
18
18
 
19
19
 
20
20
  Copyright (c) 2009 Robby Colvin, released under the MIT license
@@ -3,7 +3,7 @@ def export_csv(klass, options = {})
3
3
 
4
4
  opts = { :filename => klass, :parameters => {} }.merge(options)
5
5
 
6
- records = klass.find(:all, :parameters => opts[:parameters])
6
+ records = klass.find(:all, opts[:parameters])
7
7
  headers = klass.columns.collect{ |a| a.name }
8
8
  data = []
9
9
  records.each do |r|
@@ -16,6 +16,6 @@ def export_csv(klass, options = {})
16
16
  table = Ruport::Data::Table(:column_names => headers.collect{ |h| h.humanize }, :data => data)
17
17
  csv = table.to_csv
18
18
  time = Time.now
19
- filename = "#{filename}-#{time.strftime('%m%d%Y-%H%M')}.csv"
20
- send_data csv, :filename => opts[:filename], :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; #{filename}"
19
+ filename = "#{opts[:filename]}-#{time.strftime('%m%d%Y-%H%M')}.csv"
20
+ send_data csv, :filename => filename, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; #{filename}"
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geetarista-export_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robby Colvin