geetarista-export_csv 0.0.3 → 0.0.4

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.
Files changed (3) hide show
  1. data/README.rdoc +5 -4
  2. data/lib/export_csv.rb +6 -3
  3. metadata +1 -1
data/README.rdoc CHANGED
@@ -8,12 +8,13 @@ The only required parameter is the model name:
8
8
 
9
9
  export_csv(User)
10
10
 
11
- The name of the generated file can be overriden by passing it as a second option:
11
+ The name of the generated file can be overriden by passing it with the :filename option:
12
12
 
13
- export_csv(User, "User Backup")
13
+ export_csv(User, :filename => "User Backup")
14
14
 
15
- Find options may also be passed
15
+ Find options for the model may also be passed with :parameters
16
+
17
+ export_csv(User, :parameters => { :limit => 20 })
16
18
 
17
- export_csv(User, "User Backup", { :limit => 20 })
18
19
 
19
20
  Copyright (c) 2009 Robby Colvin, released under the MIT license
data/lib/export_csv.rb CHANGED
@@ -1,6 +1,9 @@
1
- def export_csv(klass, filename=klass, conditions={})
1
+ def export_csv(klass, options = {})
2
2
  require 'ruport'
3
- records = klass.find(:all, :options => options)
3
+
4
+ opts = { :filename => klass, :parameters => {} }.merge(options)
5
+
6
+ records = klass.find(:all, :parameters => opts[:parameters])
4
7
  headers = klass.columns.collect{ |a| a.name }
5
8
  data = []
6
9
  records.each do |r|
@@ -14,5 +17,5 @@ def export_csv(klass, filename=klass, conditions={})
14
17
  csv = table.to_csv
15
18
  time = Time.now
16
19
  filename = "#{filename}-#{time.strftime('%m%d%Y-%H%M')}.csv"
17
- send_data csv, :filename => filename, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; #{filename}"
20
+ send_data csv, :filename => opts[:filename], :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; #{filename}"
18
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robby Colvin