render_csv 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ render_csv (0.0.1)
5
+ rails (>= 3.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.6)
11
+ actionpack (= 3.2.6)
12
+ mail (~> 2.4.4)
13
+ actionpack (3.2.6)
14
+ activemodel (= 3.2.6)
15
+ activesupport (= 3.2.6)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.1)
19
+ rack (~> 1.4.0)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.1.3)
23
+ activemodel (3.2.6)
24
+ activesupport (= 3.2.6)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.6)
27
+ activemodel (= 3.2.6)
28
+ activesupport (= 3.2.6)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.6)
32
+ activemodel (= 3.2.6)
33
+ activesupport (= 3.2.6)
34
+ activesupport (3.2.6)
35
+ i18n (~> 0.6)
36
+ multi_json (~> 1.0)
37
+ arel (3.0.2)
38
+ builder (3.0.0)
39
+ diff-lcs (1.1.3)
40
+ erubis (2.7.0)
41
+ hike (1.2.1)
42
+ i18n (0.6.0)
43
+ journey (1.0.4)
44
+ json (1.6.7)
45
+ mail (2.4.4)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.19)
50
+ multi_json (1.3.6)
51
+ polyglot (0.3.3)
52
+ rack (1.4.1)
53
+ rack-cache (1.2)
54
+ rack (>= 0.4)
55
+ rack-ssl (1.3.2)
56
+ rack
57
+ rack-test (0.6.1)
58
+ rack (>= 1.0)
59
+ rails (3.2.6)
60
+ actionmailer (= 3.2.6)
61
+ actionpack (= 3.2.6)
62
+ activerecord (= 3.2.6)
63
+ activeresource (= 3.2.6)
64
+ activesupport (= 3.2.6)
65
+ bundler (~> 1.0)
66
+ railties (= 3.2.6)
67
+ railties (3.2.6)
68
+ actionpack (= 3.2.6)
69
+ activesupport (= 3.2.6)
70
+ rack-ssl (~> 1.3.2)
71
+ rake (>= 0.8.7)
72
+ rdoc (~> 3.4)
73
+ thor (>= 0.14.6, < 2.0)
74
+ rake (0.9.2.2)
75
+ rdoc (3.12)
76
+ json (~> 1.4)
77
+ rspec (2.10.0)
78
+ rspec-core (~> 2.10.0)
79
+ rspec-expectations (~> 2.10.0)
80
+ rspec-mocks (~> 2.10.0)
81
+ rspec-core (2.10.1)
82
+ rspec-expectations (2.10.0)
83
+ diff-lcs (~> 1.1.3)
84
+ rspec-mocks (2.10.1)
85
+ rspec-rails (2.10.1)
86
+ actionpack (>= 3.0)
87
+ activesupport (>= 3.0)
88
+ railties (>= 3.0)
89
+ rspec (~> 2.10.0)
90
+ sprockets (2.1.3)
91
+ hike (~> 1.2)
92
+ rack (~> 1.0)
93
+ tilt (~> 1.1, != 1.3.0)
94
+ sqlite3 (1.3.6)
95
+ thor (0.15.4)
96
+ tilt (1.3.3)
97
+ treetop (1.4.10)
98
+ polyglot
99
+ polyglot (>= 0.3.1)
100
+ tzinfo (0.3.33)
101
+
102
+ PLATFORMS
103
+ ruby
104
+
105
+ DEPENDENCIES
106
+ json (~> 1.6.5)
107
+ render_csv!
108
+ rspec-rails (~> 2.10.0)
109
+ sqlite3 (~> 1.3.6)
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # render_csv
2
+
3
+ Rails 3 CSV renderer for ActiveRecord collections
4
+
5
+ ## What is it?
6
+
7
+ The CSV renderer allows you to render any collection as CSV data.
8
+
9
+ ```ruby
10
+ class LocationsController < ApplicationController
11
+ def index
12
+ @locations = Location.all
13
+
14
+ respond_to do |format|
15
+ format.csv { render :csv => @locations }
16
+ end
17
+ end
18
+ end
19
+ ```
20
+
21
+ Will render a CSV file similar to:
22
+
23
+ <table>
24
+ <tr>
25
+ <th>name</th><th>address</th><th>city</th><th>state</th><th>zip</th><th>created_at</th><th>updated_at</th>
26
+ </tr>
27
+ <tr>
28
+ <td>Pete's House</td><td>555 House Ln</td><td>Burlington</td><td>VT</td><td>05401</td><td>2011-07-26 03:12:44 UTC</td><td>2011-07-26 03:12:44 UTC</td>
29
+ </tr>
30
+ <tr>
31
+ <td>Sebastians's House</td><td>123 Pup St</td><td>Burlington</td><td>VT</td><td>05401</td><td>2011-07-26 03:30:44 UTC</td><td>2011-07-26 03:30:44 UTC</td>
32
+ </tr>
33
+ <tr>
34
+ <td>Someone Else</td><td>999 Herp Derp</td><td>Burlington</td><td>VT</td><td>05401</td><td>2011-07-26 03:30:44 UTC</td><td>2011-07-26 03:30:44 UTC</td>
35
+ </tr>
36
+ </table>
37
+
38
+ ## Usage Options
39
+
40
+ There are a few options you can use to customize which columns are included in the CSV file
41
+
42
+ ### Exclude columns
43
+
44
+ ```ruby
45
+ respond_to do |format|
46
+ format.csv { render :csv => @locations, :except => [:id] }
47
+ end
48
+ ```
49
+
50
+ ### Limit columns
51
+
52
+ ```ruby
53
+ respond_to do |format|
54
+ format.csv { render :csv => @locations, :only => [:address, :zip] }
55
+ end
56
+ ```
57
+
58
+ ### Add methods as columns
59
+
60
+ ```ruby
61
+ respond_to do |format|
62
+ format.csv { render :csv => @locations, :add_methods => [:method1, :method2] }
63
+ end
64
+ ```
65
+
66
+ ### Add methods as columns and exclude columns
67
+
68
+ ```ruby
69
+ respond_to do |format|
70
+ format.csv { render :csv => @locations, :except => [:id], :add_methods => [:method1, :method2] }
71
+ end
72
+ ```
73
+
74
+ ## Contributing to render_csv
75
+
76
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
77
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
78
+ * Fork the project
79
+ * Start a feature/bugfix branch
80
+ * Commit and push until you are happy with your contribution
81
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
82
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
83
+
84
+ ## Copyright
85
+
86
+ Copyright (c) 2011-2012 Peter Brown. See LICENSE.txt for
87
+ further details.
88
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ module RenderCsv
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/render_csv/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Peter Brown"]
6
+ gem.email = ["github@lette.us"]
7
+ gem.description = "Adds a custom CSV renderer to Rails 3 applications"
8
+ gem.summary = "Adds a custom CSV renderer to Rails 3 applications"
9
+ gem.homepage = "http://github.com/beerlington/render_csv"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "render_csv"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = RenderCsv::VERSION
16
+
17
+ gem.add_dependency('rails', '>= 3.0')
18
+
19
+ gem.add_development_dependency('rspec-rails', '~> 2.10.0')
20
+ gem.add_development_dependency('sqlite3', '~> 1.3.6')
21
+ gem.add_development_dependency('json', '~> 1.6.5')
22
+
23
+ end
@@ -0,0 +1,73 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Array do
4
+ let(:sebastian) { Dog.create!(:name => 'Sebastian', :age => 3, :weight => 76.8) }
5
+ let(:ruby) { Dog.create!(:name => 'Ruby', :age => 3, :weight => 68.2) }
6
+ let(:shelby) { Dog.create!(:name => 'Shelby', :age => 5, :weight => 64.0) }
7
+ let(:array) { [sebastian,ruby,shelby] }
8
+
9
+ it 'should return an empty string if array is empty' do
10
+ [].to_csv.should eql('')
11
+ end
12
+
13
+ it 'should return return a csv of the array if it is not an AR class' do
14
+ [1,2,3].to_csv.should eql('1,2,3')
15
+ end
16
+
17
+ it 'should return a all columns with no option' do
18
+ csv = ["id,name,age,weight"]
19
+ csv << ["#{sebastian.id},Sebastian,3,76.8"]
20
+ csv << ["#{ruby.id},Ruby,3,68.2"]
21
+ csv << ["#{shelby.id},Shelby,5,64.0"]
22
+
23
+ array.to_csv.should eql(csv.join("\n"))
24
+ end
25
+
26
+ it 'should include only columns specified' do
27
+ csv = ["name,age"]
28
+ csv << ["Sebastian,3"]
29
+ csv << ["Ruby,3"]
30
+ csv << ["Shelby,5"]
31
+
32
+ options = {:only => [:name, :age] }
33
+
34
+ array.to_csv(options).should eql(csv.join("\n"))
35
+
36
+ end
37
+
38
+ it 'should exclude columns specified' do
39
+ csv = ["id,name,weight"]
40
+ csv << ["#{sebastian.id},Sebastian,76.8"]
41
+ csv << ["#{ruby.id},Ruby,68.2"]
42
+ csv << ["#{shelby.id},Shelby,64.0"]
43
+
44
+ options = {:except => [:age] }
45
+
46
+ array.to_csv(options).should eql(csv.join("\n"))
47
+ end
48
+
49
+ it 'should include method values when specified' do
50
+ csv = ["id,name,age,weight,human_age"]
51
+ csv << ["#{sebastian.id},Sebastian,3,76.8,25"]
52
+ csv << ["#{ruby.id},Ruby,3,68.2,25"]
53
+ csv << ["#{shelby.id},Shelby,5,64.0,33"]
54
+
55
+ options = {:add_methods => [:human_age] }
56
+
57
+ array.to_csv(options).should eql(csv.join("\n"))
58
+
59
+ end
60
+
61
+ it 'should include method values with other options' do
62
+ csv = ["age,weight,human_age"]
63
+ csv << ["3,76.8,25"]
64
+ csv << ["3,68.2,25"]
65
+ csv << ["5,64.0,33"]
66
+
67
+ options = {:except => [:id,:name], :add_methods => [:human_age] }
68
+
69
+ array.to_csv(options).should eql(csv.join("\n"))
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rspec'
5
+ require 'active_record'
6
+ require 'render_csv'
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ config.color_enabled = true
14
+ end
15
+
16
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
17
+
18
+ ActiveRecord::Schema.define(:version => 1) do
19
+ create_table :dogs, :force => true do |t|
20
+ t.string :name
21
+ t.integer :age
22
+ t.float :weight
23
+ end
24
+ end
25
+
26
+ class Dog < ActiveRecord::Base
27
+ validates_presence_of :name, :age, :weight
28
+
29
+ def human_age
30
+ if age <= 2
31
+ (age * 10.5).to_i
32
+ else
33
+ (2 * 10.5 + (age - 2) * 4).to_i
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,89 +9,94 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-30 00:00:00.000000000Z
12
+ date: 2012-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70359766159360 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.0.0
21
+ version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70359766159360
25
- - !ruby/object:Gem::Dependency
26
- name: sqlite3
27
- requirement: &70359766158760 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
28
25
  none: false
29
26
  requirements:
30
27
  - - ! '>='
31
28
  - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70359766158760
29
+ version: '3.0'
36
30
  - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &70359766158260 !ruby/object:Gem::Requirement
31
+ name: rspec-rails
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
34
  requirements:
41
35
  - - ~>
42
36
  - !ruby/object:Gem::Version
43
- version: 2.6.0
37
+ version: 2.10.0
44
38
  type: :development
45
39
  prerelease: false
46
- version_requirements: *70359766158260
47
- - !ruby/object:Gem::Dependency
48
- name: bundler
49
- requirement: &70359766157780 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
50
41
  none: false
51
42
  requirements:
52
43
  - - ~>
53
44
  - !ruby/object:Gem::Version
54
- version: 1.0.0
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70359766157780
45
+ version: 2.10.0
58
46
  - !ruby/object:Gem::Dependency
59
- name: jeweler
60
- requirement: &70359766157260 !ruby/object:Gem::Requirement
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
61
49
  none: false
62
50
  requirements:
63
51
  - - ~>
64
52
  - !ruby/object:Gem::Version
65
- version: 1.6.4
53
+ version: 1.3.6
66
54
  type: :development
67
55
  prerelease: false
68
- version_requirements: *70359766157260
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.6
69
62
  - !ruby/object:Gem::Dependency
70
- name: rcov
71
- requirement: &70359766156760 !ruby/object:Gem::Requirement
63
+ name: json
64
+ requirement: !ruby/object:Gem::Requirement
72
65
  none: false
73
66
  requirements:
74
- - - ! '>='
67
+ - - ~>
75
68
  - !ruby/object:Gem::Version
76
- version: '0'
69
+ version: 1.6.5
77
70
  type: :development
78
71
  prerelease: false
79
- version_requirements: *70359766156760
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.6.5
80
78
  description: Adds a custom CSV renderer to Rails 3 applications
81
- email: github@lette.us
79
+ email:
80
+ - github@lette.us
82
81
  executables: []
83
82
  extensions: []
84
- extra_rdoc_files:
85
- - LICENSE.txt
86
- - README.rdoc
83
+ extra_rdoc_files: []
87
84
  files:
85
+ - .gitignore
86
+ - .rspec
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
88
92
  - lib/render_csv.rb
89
93
  - lib/render_csv/extension.rb
90
- - LICENSE.txt
91
- - README.rdoc
94
+ - lib/render_csv/version.rb
95
+ - render_csv.gemspec
96
+ - spec/lib/array_spec.rb
97
+ - spec/spec_helper.rb
92
98
  homepage: http://github.com/beerlington/render_csv
93
- licenses:
94
- - MIT
99
+ licenses: []
95
100
  post_install_message:
96
101
  rdoc_options: []
97
102
  require_paths:
@@ -104,17 +109,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
109
  version: '0'
105
110
  segments:
106
111
  - 0
107
- hash: -2383263138295080423
112
+ hash: 3585876132328497061
108
113
  required_rubygems_version: !ruby/object:Gem::Requirement
109
114
  none: false
110
115
  requirements:
111
116
  - - ! '>='
112
117
  - !ruby/object:Gem::Version
113
118
  version: '0'
119
+ segments:
120
+ - 0
121
+ hash: 3585876132328497061
114
122
  requirements: []
115
123
  rubyforge_project:
116
- rubygems_version: 1.8.6
124
+ rubygems_version: 1.8.24
117
125
  signing_key:
118
126
  specification_version: 3
119
- summary: Provides CSV rendering support to Rails 3 applications
120
- test_files: []
127
+ summary: Adds a custom CSV renderer to Rails 3 applications
128
+ test_files:
129
+ - spec/lib/array_spec.rb
130
+ - spec/spec_helper.rb
data/README.rdoc DELETED
@@ -1,19 +0,0 @@
1
- = render_csv
2
-
3
- Description goes here.
4
-
5
- == Contributing to render_csv
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
- * Fork the project
10
- * Start a feature/bugfix branch
11
- * Commit and push until you are happy with your contribution
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2011 Peter Brown. See LICENSE.txt for
18
- further details.
19
-