comma 0.4.3 → 0.5.2
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.
- data/.gitignore +4 -0
- data/.rvmrc +5 -0
- data/Appraisals +9 -0
- data/Gemfile +2 -9
- data/Gemfile.lock +23 -21
- data/README.rdoc +14 -0
- data/Rakefile +3 -37
- data/comma.gemspec +20 -63
- data/gemfiles/activesupport2.gemfile +8 -0
- data/gemfiles/activesupport2.gemfile.lock +39 -0
- data/gemfiles/activesupport3.gemfile +8 -0
- data/gemfiles/activesupport3.gemfile.lock +52 -0
- data/lib/comma.rb +28 -16
- data/lib/comma/association_proxy.rb +1 -0
- data/lib/comma/generator.rb +3 -3
- data/lib/comma/named_scope.rb +1 -0
- data/lib/comma/object.rb +7 -1
- data/lib/comma/relation.rb +5 -0
- data/lib/comma/render_as_csv.rb +5 -4
- data/lib/comma/version.rb +3 -0
- data/spec/comma/ar_spec.rb +23 -16
- data/spec/comma/comma_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -1
- data/spec/support/database.yml +4 -0
- metadata +62 -57
- data/VERSION +0 -1
data/.gitignore
ADDED
data/.rvmrc
ADDED
data/Appraisals
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
comma (0.5.2)
|
5
|
+
fastercsv (= 1.5.4)
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: http://rubygems.org/
|
3
9
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
activesupport (2.3.10)
|
7
|
-
diff-lcs (1.1.2)
|
8
|
-
fastercsv (1.5.4)
|
9
|
-
git (1.2.5)
|
10
|
-
jeweler (1.6.0)
|
11
|
-
bundler (~> 1.0.0)
|
12
|
-
git (>= 1.2.5)
|
10
|
+
appraisal (0.4.0)
|
11
|
+
bundler
|
13
12
|
rake
|
13
|
+
diff-lcs (1.1.3)
|
14
|
+
fastercsv (1.5.4)
|
14
15
|
rake (0.8.7)
|
15
|
-
rspec (2.
|
16
|
-
rspec-core (~> 2.
|
17
|
-
rspec-expectations (~> 2.
|
18
|
-
rspec-mocks (~> 2.
|
19
|
-
rspec-core (2.
|
20
|
-
rspec-expectations (2.
|
16
|
+
rspec (2.7.0)
|
17
|
+
rspec-core (~> 2.7.0)
|
18
|
+
rspec-expectations (~> 2.7.0)
|
19
|
+
rspec-mocks (~> 2.7.0)
|
20
|
+
rspec-core (2.7.1)
|
21
|
+
rspec-expectations (2.7.0)
|
21
22
|
diff-lcs (~> 1.1.2)
|
22
|
-
rspec-mocks (2.
|
23
|
+
rspec-mocks (2.7.0)
|
24
|
+
sqlite3 (1.3.5)
|
23
25
|
|
24
26
|
PLATFORMS
|
25
27
|
ruby
|
26
28
|
|
27
29
|
DEPENDENCIES
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
appraisal (>= 0.4.0)
|
31
|
+
comma!
|
32
|
+
rake (= 0.8.7)
|
33
|
+
rspec (~> 2.7.0)
|
34
|
+
sqlite3 (~> 1.3.4)
|
data/README.rdoc
CHANGED
@@ -223,4 +223,18 @@ If you're on Ruby 1.8.*, the FasterCSV gem is recommended for performance reason
|
|
223
223
|
|
224
224
|
If you have any questions or suggestions for Comma, please feel free to contact me at crafterm@redartisan.com, all feedback welcome!
|
225
225
|
|
226
|
+
== TESTING
|
227
|
+
|
228
|
+
This gem has been tested on :
|
229
|
+
Ruby 1.8.7, 1.9.2
|
230
|
+
|
231
|
+
And on Rails 2.x and 3.x.
|
232
|
+
|
233
|
+
To run the test suite across multiple gem file sets, we're using [Appraisal](https://github.com/thoughtbot/appraisal), use the following commands :
|
234
|
+
|
235
|
+
```
|
236
|
+
bundle install
|
237
|
+
bundle exec rake appraisals:install
|
238
|
+
bundle exec rake appraisals spec
|
239
|
+
```
|
226
240
|
|
data/Rakefile
CHANGED
@@ -1,25 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake'
|
1
|
+
require "bundler/gem_tasks"
|
11
2
|
|
12
|
-
require '
|
13
|
-
Jeweler::Tasks.new do |gem|
|
14
|
-
gem.name = "comma"
|
15
|
-
gem.summary = "Ruby Comma Seperated Values generation library"
|
16
|
-
gem.description = "Ruby Comma Seperated Values generation library"
|
17
|
-
gem.email = "crafterm@redartisan.com"
|
18
|
-
gem.rubyforge_project = 'comma'
|
19
|
-
gem.homepage = "http://github.com/crafterm/comma"
|
20
|
-
gem.authors = ["Marcus Crafter"]
|
21
|
-
end
|
22
|
-
Jeweler::RubygemsDotOrgTasks.new
|
3
|
+
require 'appraisal'
|
23
4
|
|
24
5
|
require 'rspec/core'
|
25
6
|
require 'rspec/core/rake_task'
|
@@ -27,19 +8,4 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
27
8
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
28
9
|
end
|
29
10
|
|
30
|
-
|
31
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
-
spec.rcov = true
|
33
|
-
end
|
34
|
-
|
35
|
-
task :default => :spec
|
36
|
-
|
37
|
-
require 'rake/rdoctask'
|
38
|
-
Rake::RDocTask.new do |rdoc|
|
39
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
-
|
41
|
-
rdoc.rdoc_dir = 'rdoc'
|
42
|
-
rdoc.title = "awesome #{version}"
|
43
|
-
rdoc.rdoc_files.include('README*')
|
44
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
-
end
|
11
|
+
task :default => :spec
|
data/comma.gemspec
CHANGED
@@ -1,71 +1,28 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "comma/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
6
|
+
s.name = "comma"
|
7
|
+
s.version = Comma::VERSION
|
8
|
+
s.authors = ["Marcus Crafter", "Tom Meier"]
|
9
|
+
s.email = ["crafterm@redartisan.com", "tom@venombytes.com"]
|
10
|
+
s.homepage = "http://github.com/crafterm/comma"
|
11
|
+
s.summary = %q{Ruby Comma Seperated Values generation library}
|
13
12
|
s.description = %q{Ruby Comma Seperated Values generation library}
|
14
|
-
|
15
|
-
s.
|
16
|
-
|
17
|
-
|
18
|
-
s.files
|
19
|
-
|
20
|
-
"Gemfile.lock",
|
21
|
-
"MIT-LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"comma.gemspec",
|
26
|
-
"init.rb",
|
27
|
-
"lib/comma.rb",
|
28
|
-
"lib/comma/array.rb",
|
29
|
-
"lib/comma/association_proxy.rb",
|
30
|
-
"lib/comma/extractors.rb",
|
31
|
-
"lib/comma/generator.rb",
|
32
|
-
"lib/comma/named_scope.rb",
|
33
|
-
"lib/comma/object.rb",
|
34
|
-
"lib/comma/render_as_csv.rb",
|
35
|
-
"spec/comma/ar_spec.rb",
|
36
|
-
"spec/comma/comma_spec.rb",
|
37
|
-
"spec/comma/extractors_spec.rb",
|
38
|
-
"spec/spec.opts",
|
39
|
-
"spec/spec_helper.rb"
|
40
|
-
]
|
41
|
-
s.homepage = %q{http://github.com/crafterm/comma}
|
13
|
+
|
14
|
+
s.rubyforge_project = "comma"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
42
19
|
s.require_paths = ["lib"]
|
43
|
-
s.rubyforge_project = %q{comma}
|
44
|
-
s.rubygems_version = %q{1.4.2}
|
45
|
-
s.summary = %q{Ruby Comma Seperated Values generation library}
|
46
20
|
|
47
|
-
|
48
|
-
s.specification_version = 3
|
21
|
+
s.add_runtime_dependency(%q<fastercsv>, ["1.5.4"])
|
49
22
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
55
|
-
s.add_development_dependency(%q<activerecord>, [">= 2.2.2"])
|
56
|
-
else
|
57
|
-
s.add_dependency(%q<activesupport>, [">= 2.2.2"])
|
58
|
-
s.add_dependency(%q<fastercsv>, [">= 0"])
|
59
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6"])
|
60
|
-
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
61
|
-
s.add_dependency(%q<activerecord>, [">= 2.2.2"])
|
62
|
-
end
|
63
|
-
else
|
64
|
-
s.add_dependency(%q<activesupport>, [">= 2.2.2"])
|
65
|
-
s.add_dependency(%q<fastercsv>, [">= 0"])
|
66
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6"])
|
67
|
-
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
68
|
-
s.add_dependency(%q<activerecord>, [">= 2.2.2"])
|
69
|
-
end
|
70
|
-
end
|
23
|
+
s.add_development_dependency(%q<rake>, ["0.8.7"])
|
24
|
+
s.add_development_dependency('sqlite3', '~> 1.3.4')
|
25
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.7.0"])
|
26
|
+
s.add_development_dependency(%q<appraisal>, [">= 0.4.0"])
|
71
27
|
|
28
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/tom/Development/Projects/comma
|
3
|
+
specs:
|
4
|
+
comma (0.4.2)
|
5
|
+
fastercsv (= 1.5.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activerecord (2.3.14)
|
11
|
+
activesupport (= 2.3.14)
|
12
|
+
activesupport (2.3.14)
|
13
|
+
appraisal (0.4.0)
|
14
|
+
bundler
|
15
|
+
rake
|
16
|
+
diff-lcs (1.1.3)
|
17
|
+
fastercsv (1.5.4)
|
18
|
+
rake (0.8.7)
|
19
|
+
rspec (2.7.0)
|
20
|
+
rspec-core (~> 2.7.0)
|
21
|
+
rspec-expectations (~> 2.7.0)
|
22
|
+
rspec-mocks (~> 2.7.0)
|
23
|
+
rspec-core (2.7.1)
|
24
|
+
rspec-expectations (2.7.0)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
rspec-mocks (2.7.0)
|
27
|
+
sqlite3 (1.3.5)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
activerecord (< 3)
|
34
|
+
activesupport (< 3)
|
35
|
+
appraisal (>= 0.4.0)
|
36
|
+
comma!
|
37
|
+
rake (= 0.8.7)
|
38
|
+
rspec (~> 2.7.0)
|
39
|
+
sqlite3 (~> 1.3.4)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/tom/Development/Projects/comma
|
3
|
+
specs:
|
4
|
+
comma (0.4.2)
|
5
|
+
fastercsv (= 1.5.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (3.1.3)
|
11
|
+
activesupport (= 3.1.3)
|
12
|
+
builder (~> 3.0.0)
|
13
|
+
i18n (~> 0.6)
|
14
|
+
activerecord (3.1.3)
|
15
|
+
activemodel (= 3.1.3)
|
16
|
+
activesupport (= 3.1.3)
|
17
|
+
arel (~> 2.2.1)
|
18
|
+
tzinfo (~> 0.3.29)
|
19
|
+
activesupport (3.1.3)
|
20
|
+
multi_json (~> 1.0)
|
21
|
+
appraisal (0.4.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
arel (2.2.1)
|
25
|
+
builder (3.0.0)
|
26
|
+
diff-lcs (1.1.3)
|
27
|
+
fastercsv (1.5.4)
|
28
|
+
i18n (0.6.0)
|
29
|
+
multi_json (1.0.4)
|
30
|
+
rake (0.8.7)
|
31
|
+
rspec (2.7.0)
|
32
|
+
rspec-core (~> 2.7.0)
|
33
|
+
rspec-expectations (~> 2.7.0)
|
34
|
+
rspec-mocks (~> 2.7.0)
|
35
|
+
rspec-core (2.7.1)
|
36
|
+
rspec-expectations (2.7.0)
|
37
|
+
diff-lcs (~> 1.1.2)
|
38
|
+
rspec-mocks (2.7.0)
|
39
|
+
sqlite3 (1.3.5)
|
40
|
+
tzinfo (0.3.31)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
activerecord (> 3)
|
47
|
+
activesupport (> 3)
|
48
|
+
appraisal (>= 0.4.0)
|
49
|
+
comma!
|
50
|
+
rake (= 0.8.7)
|
51
|
+
rspec (~> 2.7.0)
|
52
|
+
sqlite3 (~> 1.3.4)
|
data/lib/comma.rb
CHANGED
@@ -1,40 +1,52 @@
|
|
1
|
-
# conditional loading of activesupport
|
2
|
-
if defined? Rails and (Rails.version.split('.').map(&:to_i) <=> [2,3,5]) < 0
|
3
|
-
require 'activesupport'
|
4
|
-
else
|
5
|
-
require 'active_support/core_ext/class/inheritable_attributes'
|
6
|
-
end
|
7
|
-
|
8
1
|
# load the right csv library
|
9
2
|
if RUBY_VERSION >= '1.9'
|
10
3
|
require 'csv'
|
11
|
-
|
4
|
+
CSV_HANDLER = CSV
|
12
5
|
else
|
13
6
|
begin
|
14
7
|
# try faster csv
|
15
8
|
require 'fastercsv'
|
9
|
+
CSV_HANDLER = FasterCSV
|
16
10
|
rescue Exception => e
|
11
|
+
fail_message = "FasterCSV not installed, please `gem install fastercsv` for faster processing"
|
17
12
|
if defined? Rails
|
18
|
-
Rails.logger.info
|
13
|
+
Rails.logger.info fail_message
|
19
14
|
else
|
20
|
-
puts
|
15
|
+
puts fail_message
|
21
16
|
end
|
22
17
|
require 'csv'
|
23
|
-
|
18
|
+
CSV_HANDLER = CSV
|
24
19
|
end
|
25
20
|
end
|
26
21
|
|
22
|
+
#TODO : Rails 2.3.x Deprecation
|
23
|
+
# conditional loading of activesupport
|
24
|
+
if defined? Rails and (Rails.version.split('.').map(&:to_i) <=> [2,3,5]) < 0
|
25
|
+
require 'activesupport'
|
26
|
+
else
|
27
|
+
require 'active_support/core_ext/class/inheritable_attributes'
|
28
|
+
end
|
29
|
+
|
30
|
+
if defined?(ActiveRecord)
|
31
|
+
require 'comma/association_proxy'
|
32
|
+
|
33
|
+
#TODO : Rails 2.3.x Deprecation
|
34
|
+
if defined?(ActiveRecord::Relation)
|
35
|
+
#Rails 3.x relations
|
36
|
+
require 'comma/relation'
|
37
|
+
elsif defined?(ActiveRecord::NamedScope::Scope)
|
38
|
+
#Rails 2.x scoping
|
39
|
+
require 'comma/named_scope'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
27
44
|
require 'comma/extractors'
|
28
45
|
require 'comma/generator'
|
29
46
|
require 'comma/array'
|
30
47
|
require 'comma/object'
|
31
48
|
require 'comma/render_as_csv'
|
32
49
|
|
33
|
-
if defined?(ActiveRecord)
|
34
|
-
require 'comma/named_scope'
|
35
|
-
require 'comma/association_proxy'
|
36
|
-
end
|
37
|
-
|
38
50
|
if defined?(RenderAsCSV) && defined?(ActionController)
|
39
51
|
ActionController::Base.send :include, RenderAsCSV
|
40
52
|
end
|
data/lib/comma/generator.rb
CHANGED
@@ -16,19 +16,19 @@ module Comma
|
|
16
16
|
|
17
17
|
def run(iterator_method)
|
18
18
|
if @filename
|
19
|
-
|
19
|
+
CSV_HANDLER.open(@filename, 'w', @options){ |csv| append_csv(csv, iterator_method) } and return true
|
20
20
|
else
|
21
|
-
|
21
|
+
CSV_HANDLER.generate(@options){ |csv| append_csv(csv, iterator_method) }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
26
|
+
|
26
27
|
def append_csv(csv, iterator_method)
|
27
28
|
return '' if @instance.empty?
|
28
29
|
unless @options.has_key?(:write_headers) && !@options[:write_headers]
|
29
30
|
csv << @instance.first.to_comma_headers(@style)
|
30
31
|
end
|
31
|
-
|
32
32
|
@instance.send(iterator_method) do |object|
|
33
33
|
csv << object.to_comma(@style)
|
34
34
|
end
|
data/lib/comma/named_scope.rb
CHANGED
data/lib/comma/object.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
class Object
|
2
|
-
|
2
|
+
if Class.respond_to?(:class_attribute)
|
3
|
+
class_attribute :comma_formats
|
4
|
+
else
|
5
|
+
#TODO : Rails 2.3.x Deprecation
|
6
|
+
#Deprecated method for class accessors - Maintained for those still on Rails 2.3.x
|
7
|
+
class_inheritable_accessor :comma_formats
|
8
|
+
end
|
3
9
|
|
4
10
|
def self.comma(style = :default, &block)
|
5
11
|
(self.comma_formats ||= {})[style] = block
|
data/lib/comma/render_as_csv.rb
CHANGED
@@ -33,6 +33,7 @@ else
|
|
33
33
|
|
34
34
|
protected
|
35
35
|
|
36
|
+
#TODO : Rails 2.3.x Deprecation
|
36
37
|
def render_stream(options)
|
37
38
|
status = options[:status]
|
38
39
|
content = options[:content]
|
@@ -41,14 +42,14 @@ else
|
|
41
42
|
# If Rails 2.x
|
42
43
|
if defined? Rails and (Rails.version.split('.').map(&:to_i) <=> [2,3,5]) < 0
|
43
44
|
render :status => status, :text => Proc.new { |response, output|
|
44
|
-
output.write
|
45
|
-
content.each { |line| output.write
|
45
|
+
output.write CSV_HANDLER.generate_line(content.first.to_comma_headers(style))
|
46
|
+
content.each { |line| output.write CSV_HANDLER.generate_line(line.to_comma(style)) }
|
46
47
|
}
|
47
48
|
else # If Rails 3.x
|
48
49
|
self.status = status
|
49
50
|
self.response_body = proc { |response, output|
|
50
|
-
output.write
|
51
|
-
content.each { |line| output.write
|
51
|
+
output.write CSV_HANDLER.generate_line(content.first.to_comma_headers(style))
|
52
|
+
content.each { |line| output.write CSV_HANDLER.generate_line(line.to_comma(style)) }
|
52
53
|
}
|
53
54
|
end
|
54
55
|
end
|
data/spec/comma/ar_spec.rb
CHANGED
@@ -1,30 +1,37 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe Comma, 'generating CSV from an ActiveRecord object' do
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
class Person < ActiveRecord::Base
|
6
|
+
#TODO : Rails 2.3.x Deprecation
|
7
|
+
if defined?(ActiveRecord::Relation)
|
8
|
+
#Rails 3.x
|
9
|
+
scope :teenagers, lambda { {:conditions => { :age => 13..19 }} }
|
10
|
+
else
|
11
|
+
#Rails 2.x
|
6
12
|
named_scope :teenagers, :conditions => { :age => 13..19 }
|
7
|
-
comma do
|
8
|
-
name
|
9
|
-
age
|
10
|
-
end
|
11
13
|
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
+
comma do
|
16
|
+
name
|
17
|
+
age
|
18
|
+
end
|
19
|
+
|
15
20
|
end
|
16
21
|
|
17
|
-
before do
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
before(:all) do
|
23
|
+
#Setup AR model in memory
|
24
|
+
ActiveRecord::Base.connection.create_table :people, :force => true do |table|
|
25
|
+
table.column :name, :string
|
26
|
+
table.column :age, :integer
|
27
|
+
end
|
28
|
+
Person.reset_column_information
|
21
29
|
end
|
22
30
|
|
23
|
-
describe
|
31
|
+
describe "case" do
|
24
32
|
before do
|
25
|
-
|
26
|
-
|
27
|
-
Person.stub!(:calculate).with(:count, :all, {}).and_return people.size
|
33
|
+
@person = Person.new(:age => 18, :name => 'Junior')
|
34
|
+
@person.save!
|
28
35
|
end
|
29
36
|
|
30
37
|
it 'should extend ActiveRecord::NamedScope::Scope to add a #to_comma method which will return CSV content for objects within the scope' do
|
data/spec/comma/comma_spec.rb
CHANGED
@@ -201,12 +201,12 @@ describe Comma, 'to_comma data/headers object extensions' do
|
|
201
201
|
header, foo = Array(@foo).to_comma.split("\n")
|
202
202
|
header.should == ['Content', 'Truncated Content', 'Created at', 'Updated at', 'Created Custom Label', 'Updated at Custom Label'].join(',')
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
it 'should put headers in place when forced' do
|
206
206
|
header, foo = Array(@foo).to_comma(:write_headers => true).split("\n")
|
207
207
|
header.should == ['Content', 'Truncated Content', 'Created at', 'Updated at', 'Created Custom Label', 'Updated at Custom Label'].join(',')
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
it 'should not write headers if specified' do
|
211
211
|
header, foo = Array(@foo).to_comma(:write_headers => false).split("\n")
|
212
212
|
header.should == [@content, @content[0..10], @time.to_s(:db), @time.to_s(:db), @time.to_s(:short), @time.to_s(:short)].join(',')
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rspec'
|
3
3
|
require 'active_record'
|
4
|
+
|
4
5
|
ActiveRecord::ActiveRecordError # http://tinyurl.com/24f84gf
|
5
6
|
|
6
7
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
7
8
|
|
8
|
-
|
9
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/support/database.yml'))
|
10
|
+
ActiveRecord::Base.establish_connection(config['test'])
|
9
11
|
|
12
|
+
require 'comma'
|
10
13
|
|
11
14
|
class Book
|
12
15
|
attr_accessor :name, :description, :isbn
|
metadata
CHANGED
@@ -1,116 +1,117 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 2
|
9
|
+
version: 0.5.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Marcus Crafter
|
13
|
+
- Tom Meier
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-02-18 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
none: false
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
|
-
- - "
|
24
|
+
- - "="
|
26
25
|
- !ruby/object:Gem::Version
|
27
|
-
hash: 3
|
28
26
|
segments:
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
version:
|
33
|
-
|
27
|
+
- 1
|
28
|
+
- 5
|
29
|
+
- 4
|
30
|
+
version: 1.5.4
|
31
|
+
requirement: *id001
|
32
|
+
name: fastercsv
|
34
33
|
prerelease: false
|
35
|
-
version_requirements: *id001
|
36
34
|
type: :runtime
|
37
35
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
39
|
-
none: false
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
|
-
- - "
|
38
|
+
- - "="
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
40
|
segments:
|
45
41
|
- 0
|
46
|
-
|
47
|
-
|
42
|
+
- 8
|
43
|
+
- 7
|
44
|
+
version: 0.8.7
|
45
|
+
requirement: *id002
|
46
|
+
name: rake
|
48
47
|
prerelease: false
|
49
|
-
|
50
|
-
type: :runtime
|
48
|
+
type: :development
|
51
49
|
- !ruby/object:Gem::Dependency
|
52
|
-
|
53
|
-
none: false
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
52
|
- - ~>
|
56
53
|
- !ruby/object:Gem::Version
|
57
|
-
hash: 3
|
58
54
|
segments:
|
59
55
|
- 1
|
60
|
-
-
|
61
|
-
|
62
|
-
|
56
|
+
- 3
|
57
|
+
- 4
|
58
|
+
version: 1.3.4
|
59
|
+
requirement: *id003
|
60
|
+
name: sqlite3
|
63
61
|
prerelease: false
|
64
|
-
version_requirements: *id003
|
65
62
|
type: :development
|
66
63
|
- !ruby/object:Gem::Dependency
|
67
|
-
|
68
|
-
none: false
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
69
65
|
requirements:
|
70
66
|
- - ~>
|
71
67
|
- !ruby/object:Gem::Version
|
72
|
-
hash: 3
|
73
68
|
segments:
|
74
69
|
- 2
|
75
|
-
-
|
70
|
+
- 7
|
76
71
|
- 0
|
77
|
-
version: 2.
|
72
|
+
version: 2.7.0
|
73
|
+
requirement: *id004
|
78
74
|
name: rspec
|
79
75
|
prerelease: false
|
80
|
-
version_requirements: *id004
|
81
76
|
type: :development
|
82
77
|
- !ruby/object:Gem::Dependency
|
83
|
-
|
84
|
-
none: false
|
78
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
80
|
- - ">="
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
hash: 3
|
89
82
|
segments:
|
90
|
-
-
|
91
|
-
-
|
92
|
-
-
|
93
|
-
version:
|
94
|
-
|
83
|
+
- 0
|
84
|
+
- 4
|
85
|
+
- 0
|
86
|
+
version: 0.4.0
|
87
|
+
requirement: *id005
|
88
|
+
name: appraisal
|
95
89
|
prerelease: false
|
96
|
-
version_requirements: *id005
|
97
90
|
type: :development
|
98
91
|
description: Ruby Comma Seperated Values generation library
|
99
|
-
email:
|
92
|
+
email:
|
93
|
+
- crafterm@redartisan.com
|
94
|
+
- tom@venombytes.com
|
100
95
|
executables: []
|
101
96
|
|
102
97
|
extensions: []
|
103
98
|
|
104
|
-
extra_rdoc_files:
|
105
|
-
|
99
|
+
extra_rdoc_files: []
|
100
|
+
|
106
101
|
files:
|
102
|
+
- .gitignore
|
103
|
+
- .rvmrc
|
104
|
+
- Appraisals
|
107
105
|
- Gemfile
|
108
106
|
- Gemfile.lock
|
109
107
|
- MIT-LICENSE
|
110
108
|
- README.rdoc
|
111
109
|
- Rakefile
|
112
|
-
- VERSION
|
113
110
|
- comma.gemspec
|
111
|
+
- gemfiles/activesupport2.gemfile
|
112
|
+
- gemfiles/activesupport2.gemfile.lock
|
113
|
+
- gemfiles/activesupport3.gemfile
|
114
|
+
- gemfiles/activesupport3.gemfile.lock
|
114
115
|
- init.rb
|
115
116
|
- lib/comma.rb
|
116
117
|
- lib/comma/array.rb
|
@@ -119,12 +120,15 @@ files:
|
|
119
120
|
- lib/comma/generator.rb
|
120
121
|
- lib/comma/named_scope.rb
|
121
122
|
- lib/comma/object.rb
|
123
|
+
- lib/comma/relation.rb
|
122
124
|
- lib/comma/render_as_csv.rb
|
125
|
+
- lib/comma/version.rb
|
123
126
|
- spec/comma/ar_spec.rb
|
124
127
|
- spec/comma/comma_spec.rb
|
125
128
|
- spec/comma/extractors_spec.rb
|
126
129
|
- spec/spec.opts
|
127
130
|
- spec/spec_helper.rb
|
131
|
+
- spec/support/database.yml
|
128
132
|
has_rdoc: true
|
129
133
|
homepage: http://github.com/crafterm/comma
|
130
134
|
licenses: []
|
@@ -135,29 +139,30 @@ rdoc_options: []
|
|
135
139
|
require_paths:
|
136
140
|
- lib
|
137
141
|
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
142
|
requirements:
|
140
143
|
- - ">="
|
141
144
|
- !ruby/object:Gem::Version
|
142
|
-
hash: 3
|
143
145
|
segments:
|
144
146
|
- 0
|
145
147
|
version: "0"
|
146
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
-
none: false
|
148
149
|
requirements:
|
149
150
|
- - ">="
|
150
151
|
- !ruby/object:Gem::Version
|
151
|
-
hash: 3
|
152
152
|
segments:
|
153
153
|
- 0
|
154
154
|
version: "0"
|
155
155
|
requirements: []
|
156
156
|
|
157
157
|
rubyforge_project: comma
|
158
|
-
rubygems_version: 1.
|
158
|
+
rubygems_version: 1.3.6
|
159
159
|
signing_key:
|
160
160
|
specification_version: 3
|
161
161
|
summary: Ruby Comma Seperated Values generation library
|
162
|
-
test_files:
|
163
|
-
|
162
|
+
test_files:
|
163
|
+
- spec/comma/ar_spec.rb
|
164
|
+
- spec/comma/comma_spec.rb
|
165
|
+
- spec/comma/extractors_spec.rb
|
166
|
+
- spec/spec.opts
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/support/database.yml
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.4.3
|