comma 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a41ecd8c05f23d5a0cdded2eccc399525d54526f
4
- data.tar.gz: 9ea499094bd3469e2b731e646118bb56f9d6924b
5
- SHA512:
6
- metadata.gz: 57cd52eada9c08da15d212f49bcb457d664ab56d01f88767f7574c0fc9d2e30c4bd7ce241b175553648d0c0810cad641ffee2e5aeebd27727a7dd1c5f2e30b33
7
- data.tar.gz: 85657ca9f963219a41ad8b8e8cf47faee67bc8aaa5f4b7f700fcd44832874d4570af9d6c6ba556f0c4da0da8ee65d91203394a5a9150f9ca969a8c3592a5f14c
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Y2Q5ZWFkMjgwMjk0OGYzNTg3MTkyMzE0NmZkYmExNjMyN2RhNzYyNw==
5
+ data.tar.gz: !binary |-
6
+ MmYzZWQyMDhhNmFjNzUzZTVlZDJiMTg3YTk3ODg5MWNjZjZlNWY4Nw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NTE2ZjcwNjA4YjY2YTIzNjFmNDkzOGRiMDkzMjgwMGM5Y2NiZmFmNTE5ZGI3
10
+ MjljMTExMDk3OGIyZjk3YzI1NDRlNzVhZGUxZDhjMjJjOWMxMjhiZTRlYzBl
11
+ ODE4N2ZkY2JhZWQ0YjU1MGQ5ZmIxN2IwYzMwODUwMDliMWUwMTA=
12
+ data.tar.gz: !binary |-
13
+ ZWNmYTk1MDgzODBmMGE4ZDk3NjVlYjFjZDdkZGY3NjQ4NGFjNDVjOWU3Mjg0
14
+ NzkxNmRkYTU5OTk1ZTk2OTQyZTI4ZTk0YzQ3NmU4OTc4ZGJlN2Y3NTE1M2Iy
15
+ ZTEzYjQxM2ZlNmMzZmViYTRkZDZkMThmODc2MTM3YjBlOGQ2ZWY=
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
+ services: mongodb
2
+
1
3
  language: ruby
2
4
  rvm:
3
5
  - 'ree'
data/Appraisals CHANGED
@@ -12,3 +12,9 @@
12
12
  gem "activerecord", version_number
13
13
  end
14
14
  end
15
+
16
+ if RUBY_VERSION >= '1.9.3'
17
+ appraise 'mongoid3.1.4' do
18
+ gem 'mongoid', '3.1.4'
19
+ end
20
+ end
data/Gemfile.lock CHANGED
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- comma (3.1.0)
4
+ comma (3.1.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activesupport (3.2.13)
11
- i18n (= 0.6.1)
10
+ activesupport (3.2.14)
11
+ i18n (~> 0.6, >= 0.6.4)
12
12
  multi_json (~> 1.0)
13
13
  appraisal (0.4.1)
14
14
  bundler
15
15
  rake
16
16
  diff-lcs (1.1.3)
17
17
  fastercsv (1.5.4)
18
- i18n (0.6.1)
18
+ i18n (0.6.5)
19
19
  multi_json (1.1.0)
20
20
  rake (0.9.2.2)
21
21
  rspec (2.8.0)
data/README.markdown CHANGED
@@ -12,7 +12,7 @@ The mainline of this project builds gems to the 3.x version series, and is compa
12
12
  * RBX 1.8 mode, 1.9 mode
13
13
  * Rails 3.x (all versions, with ActiveRecord and Mongoid support)
14
14
 
15
- [![Build Status](https://travis-ci.org/comma-csv/comma.png?branch=master)](https://travis-ci.org/comma-csv/comma)
15
+ [![Build Status](https://travis-ci.org/comma-csv/comma.png?branch=master)](https://travis-ci.org/comma-csv/comma) [![Code Climate](https://codeclimate.com/github/comma-csv/comma.png)](https://codeclimate.com/github/comma-csv/comma)
16
16
 
17
17
  ###LOOKING FOR RAILS 2?
18
18
  * Rails 2 is supported in the 'rails2' branch of this project, and versioned in the 2.x version of this gem. (https://github.com/comma-csv/comma/tree/rails2).
@@ -24,7 +24,7 @@ Comma is distributed as a gem, best installed via Bundler.
24
24
  Include the gem in your Gemfile:
25
25
 
26
26
  ```Ruby
27
- gem "comma", "~> 3.0.5"
27
+ gem "comma", "~> 3.1.0"
28
28
  ```
29
29
 
30
30
  Or, if you want to live life on the edge, you can get master from the main comma repository:
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "fastercsv", :platforms=>:ruby_18
6
+ gem "mongoid", "3.1.4"
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: /Users/tom/src/personal/comma
3
+ specs:
4
+ comma (3.1.0)
5
+ activesupport (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.14)
11
+ activesupport (= 3.2.14)
12
+ builder (~> 3.0.0)
13
+ activesupport (3.2.14)
14
+ i18n (~> 0.6, >= 0.6.4)
15
+ multi_json (~> 1.0)
16
+ appraisal (0.4.1)
17
+ bundler
18
+ rake
19
+ builder (3.0.4)
20
+ diff-lcs (1.1.3)
21
+ fastercsv (1.5.5)
22
+ i18n (0.6.5)
23
+ mongoid (3.1.4)
24
+ activemodel (~> 3.2)
25
+ moped (~> 1.4)
26
+ origin (~> 1.0)
27
+ tzinfo (~> 0.3.22)
28
+ moped (1.5.1)
29
+ multi_json (1.7.9)
30
+ origin (1.1.0)
31
+ rake (0.9.6)
32
+ rspec (2.8.0)
33
+ rspec-core (~> 2.8.0)
34
+ rspec-expectations (~> 2.8.0)
35
+ rspec-mocks (~> 2.8.0)
36
+ rspec-core (2.8.0)
37
+ rspec-expectations (2.8.0)
38
+ diff-lcs (~> 1.1.2)
39
+ rspec-mocks (2.8.0)
40
+ simplecov (0.7.1)
41
+ multi_json (~> 1.0)
42
+ simplecov-html (~> 0.7.1)
43
+ simplecov-html (0.7.1)
44
+ sqlite3 (1.3.8)
45
+ tzinfo (0.3.37)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ appraisal (~> 0.4.1)
52
+ comma!
53
+ fastercsv
54
+ mongoid (= 3.1.4)
55
+ rake (~> 0.9.2)
56
+ rspec (~> 2.8.0)
57
+ simplecov
58
+ sqlite3 (~> 1.3.4)
data/lib/comma.rb CHANGED
@@ -24,10 +24,13 @@ module Comma
24
24
  }
25
25
  end
26
26
 
27
- require 'active_support/core_ext/class/attribute'
28
- require 'active_support/core_ext/module/delegation'
29
- require 'comma/relation' if defined?(ActiveRecord::Relation)
30
- require 'comma/mongoid'
27
+ require 'active_support/lazy_load_hooks'
28
+ ActiveSupport.on_load(:active_record) do
29
+ require 'comma/relation' if defined?(ActiveRecord::Relation)
30
+ end
31
+ ActiveSupport.on_load(:mongoid) do
32
+ require 'comma/mongoid'
33
+ end
31
34
 
32
35
  require 'comma/extractors'
33
36
  require 'comma/generator'
@@ -35,13 +38,15 @@ require 'comma/array'
35
38
  require 'comma/object'
36
39
 
37
40
  #Load into Rails controllers
38
- if defined?(ActionController::Renderers) && ActionController::Renderers.respond_to?(:add)
39
- ActionController::Renderers.add :csv do |obj, options|
40
- filename = options[:filename] || 'data'
41
- extension = options[:extension] || 'csv'
42
- mime_type = options[:mime_type] || Mime::CSV
43
- #Capture any CSV optional settings passed to comma or comma specific options
44
- csv_options = options.slice(*CSV_HANDLER::DEFAULT_OPTIONS.merge(Comma::DEFAULT_OPTIONS).keys)
45
- send_data obj.to_comma(csv_options), :type => mime_type, :disposition => "attachment; filename=#{filename}.#{extension}"
41
+ ActiveSupport.on_load(:action_controller) do
42
+ if defined?(ActionController::Renderers) && ActionController::Renderers.respond_to?(:add)
43
+ ActionController::Renderers.add :csv do |obj, options|
44
+ filename = options[:filename] || 'data'
45
+ extension = options[:extension] || 'csv'
46
+ mime_type = options[:mime_type] || Mime::CSV
47
+ #Capture any CSV optional settings passed to comma or comma specific options
48
+ csv_options = options.slice(*CSV_HANDLER::DEFAULT_OPTIONS.merge(Comma::DEFAULT_OPTIONS).keys)
49
+ send_data obj.to_comma(csv_options), :type => mime_type, :disposition => "attachment; filename=#{filename}.#{extension}"
50
+ end
46
51
  end
47
52
  end
@@ -69,7 +69,7 @@ module Comma
69
69
 
70
70
  def get_association_class(model_class, association)
71
71
  model_class.respond_to?(:reflect_on_association) ?
72
- model_class.reflect_on_association(arg).klass : nil
72
+ model_class.reflect_on_association(association).klass : nil
73
73
  end
74
74
  end
75
75
 
data/lib/comma/object.rb CHANGED
@@ -6,12 +6,21 @@ class Object
6
6
  end
7
7
 
8
8
  def to_comma(style = :default)
9
- raise "No comma format for class #{self.class} defined for style #{style}" unless self.comma_formats and self.comma_formats[style]
10
- Comma::DataExtractor.new(self, style, self.class.comma_formats).results
9
+ extract_with(Comma::DataExtractor, style)
11
10
  end
12
11
 
13
12
  def to_comma_headers(style = :default)
14
- raise "No comma format for class #{self.class} defined for style #{style}" unless self.comma_formats and self.comma_formats[style]
15
- Comma::HeaderExtractor.new(self, style, self.class.comma_formats).results
13
+ extract_with(Comma::HeaderExtractor, style)
14
+ end
15
+
16
+ private
17
+
18
+ def extract_with(extractor_class, style = :default)
19
+ raise_unless_style_exists(style)
20
+ extractor_class.new(self, style, self.class.comma_formats).results
21
+ end
22
+
23
+ def raise_unless_style_exists(style)
24
+ raise "No comma format for class #{self.class} defined for style #{style}" unless self.comma_formats && self.comma_formats[style]
16
25
  end
17
26
  end
data/lib/comma/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Comma
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.1"
3
3
  end
@@ -1,69 +1,90 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'spec_helper'
3
3
 
4
- describe Comma, 'generating CSV from an ActiveRecord object' do
4
+ if defined? ActiveRecord
5
5
 
6
- class Person < ActiveRecord::Base
7
- scope :teenagers, lambda { where(:age => 13..19) }
6
+ describe Comma, 'generating CSV from an ActiveRecord object' do
8
7
 
9
- comma do
10
- name
11
- age
12
- end
8
+ class Person < ActiveRecord::Base
9
+ scope :teenagers, lambda { where(:age => 13..19) }
13
10
 
14
- end
11
+ comma do
12
+ name
13
+ age
14
+ end
15
+
16
+ has_one :job
15
17
 
16
- before(:all) do
17
- #Setup AR model in memory
18
- ActiveRecord::Base.connection.create_table :people, :force => true do |table|
19
- table.column :name, :string
20
- table.column :age, :integer
18
+ comma :issue_75 do
19
+ job :title
20
+ end
21
+ end
22
+
23
+ class Job < ActiveRecord::Base
24
+ belongs_to :person
21
25
  end
22
- Person.reset_column_information
23
- end
24
26
 
25
- describe "case" do
26
- before do
27
+ before(:all) do
28
+ #Setup AR model in memory
29
+ ActiveRecord::Base.connection.create_table :people, :force => true do |table|
30
+ table.column :name, :string
31
+ table.column :age, :integer
32
+ end
33
+ Person.reset_column_information
34
+
35
+ ActiveRecord::Base.connection.create_table :jobs, :force => true do |table|
36
+ table.column :person_id, :integer
37
+ table.column :title, :string
38
+ end
39
+ Job.reset_column_information
40
+
27
41
  @person = Person.new(:age => 18, :name => 'Junior')
28
42
  @person.save!
29
43
  end
30
44
 
31
- it 'should extend ActiveRecord::NamedScope::Scope to add a #to_comma method which will return CSV content for objects within the scope' do
32
- Person.teenagers.to_comma.should == "Name,Age\nJunior,18\n"
33
- end
45
+ describe "case" do
46
+ it 'should extend ActiveRecord::NamedScope::Scope to add a #to_comma method which will return CSV content for objects within the scope' do
47
+ Person.teenagers.to_comma.should == "Name,Age\nJunior,18\n"
48
+ end
34
49
 
35
- it 'should find in batches' do
36
- Person.teenagers.to_comma
50
+ it 'should find in batches' do
51
+ Person.teenagers.to_comma
52
+ end
37
53
  end
38
- end
39
54
 
40
- describe 'with custom value_humanizer' do
41
- before do
42
- Comma::HeaderExtractor.value_humanizer =
43
- lambda do |value, model_class|
44
- if model_class.respond_to?(:human_attribute_name)
45
- model_class.human_attribute_name(value)
46
- else
47
- value.is_a?(String) ? value : value.to_s.humanize
55
+ describe 'with custom value_humanizer' do
56
+ before do
57
+ Comma::HeaderExtractor.value_humanizer =
58
+ lambda do |value, model_class|
59
+ if model_class.respond_to?(:human_attribute_name)
60
+ model_class.human_attribute_name(value)
61
+ else
62
+ value.is_a?(String) ? value : value.to_s.humanize
63
+ end
48
64
  end
49
- end
50
65
 
51
- I18n.config.backend.store_translations(:ja, {:activerecord => {:attributes => {:person => {:age => '年齢', :name => '名前'}}}})
52
- @original_locale = I18n.locale
53
- I18n.locale = :ja
66
+ I18n.config.backend.store_translations(:ja, {:activerecord => {:attributes => {:person => {:age => '年齢', :name => '名前'}}}})
67
+ @original_locale = I18n.locale
68
+ I18n.locale = :ja
69
+ end
54
70
 
55
- Person.create(:age => 19, :name => 'John')
56
- end
71
+ after do
72
+ I18n.locale = @original_locale
57
73
 
58
- after do
59
- I18n.locale = @original_locale
74
+ Comma::HeaderExtractor.value_humanizer =
75
+ Comma::HeaderExtractor::DEFAULT_VALUE_HUMANIZER
76
+ end
60
77
 
61
- Comma::HeaderExtractor.value_humanizer =
62
- Comma::HeaderExtractor::DEFAULT_VALUE_HUMANIZER
78
+ it 'should i18n-ize header values' do
79
+ Person.teenagers.to_comma.should match(/^名前,年齢/)
80
+ end
63
81
  end
64
82
 
65
- it 'should i18n-ize header values' do
66
- Person.teenagers.to_comma.should match(/^名前,年齢/)
83
+ describe 'github issue 75' do
84
+ it 'should find association' do
85
+ lambda { Person.all.to_comma(:issue_75) }.should_not raise_error
86
+ end
67
87
  end
68
88
  end
89
+
69
90
  end
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ if defined? Mongoid
5
+
6
+ describe Comma, 'generating CSV from an Mongoid object' do
7
+
8
+ class Person
9
+ include Mongoid::Document
10
+
11
+ field :name, :type => String
12
+ field :age, :type => Integer
13
+
14
+ scope :teenagers, between(:age => 13..19)
15
+
16
+ comma do
17
+ name
18
+ age
19
+ end
20
+ end
21
+
22
+ after(:all) do
23
+ Mongoid.purge!
24
+ end
25
+
26
+ describe "case" do
27
+ before do
28
+ @person = Person.new(:age => 18, :name => 'Junior')
29
+ @person.save
30
+ end
31
+
32
+ it 'should extend ActiveRecord::NamedScope::Scope to add a #to_comma method which will return CSV content for objects within the scope' do
33
+ Person.teenagers.to_comma.should == "Name,Age\nJunior,18\n"
34
+ end
35
+
36
+ it 'should find in batches' do
37
+ Person.teenagers.to_comma
38
+ end
39
+ end
40
+ end
41
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,23 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'rubygems'
2
- require 'rspec'
3
- require 'simplecov'
3
+ $LOAD_PATH.unshift(File.expand_path(File.join(*%w{.. .. lib}), __FILE__))
4
+
5
+ begin
6
+ require 'rails'
7
+ rescue LoadError
8
+ end
4
9
 
10
+ require 'simplecov'
5
11
  SimpleCov.start do
6
12
  add_filter "spec"
7
13
  use_merging true
8
14
  merge_timeout 600
9
15
  end
10
16
 
11
- begin
17
+ require 'bundler/setup'
18
+ Bundler.require
19
+
20
+ if defined? Rails
12
21
  #Conditionally load rails app for controller tests if rspec-rails gem is installed
13
22
  require "rails_app/config/environment"
14
23
  require 'rspec/rails'
@@ -30,18 +39,24 @@ begin
30
39
  config.use_transactional_fixtures = true
31
40
  end
32
41
 
33
- rescue LoadError => e
42
+ else
34
43
  # Normal tests : Basic active record + support only calls
35
44
  SimpleCov.command_name 'rspec:without_rails'
36
45
 
37
- require 'active_record'
46
+ begin
47
+ require 'active_record'
48
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/rails_app/config/database.yml'))
49
+ ActiveRecord::Base.establish_connection(config['test'])
50
+ rescue LoadError
51
+ end
38
52
 
39
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/rails_app/config/database.yml'))
40
- ActiveRecord::Base.establish_connection(config['test'])
53
+ begin
54
+ require 'mongoid'
55
+ Mongoid.configure do |mconfig|
56
+ mconfig.sessions = {:default => {:hosts => ['localhost:27017'], :database => 'comma_test'}}
57
+ end
58
+ rescue LoadError
59
+ end
41
60
  end
42
61
 
43
- $:.unshift(File.dirname(__FILE__) + '/../lib')
44
-
45
- require 'comma'
46
-
47
- require File.expand_path('../../spec/non_rails_app/ruby_classes' , __FILE__)
62
+ require File.expand_path('../../spec/non_rails_app/ruby_classes' , __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comma
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Crafter
@@ -9,20 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-17 00:00:00.000000000 Z
12
+ date: 2013-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ! '>='
19
19
  - !ruby/object:Gem::Version
20
20
  version: 3.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ! '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: 3.0.0
28
28
  - !ruby/object:Gem::Dependency
@@ -85,14 +85,14 @@ dependencies:
85
85
  name: simplecov
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ! '>='
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - '>='
95
+ - - ! '>='
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  description: Ruby Comma Seperated Values generation library
@@ -122,6 +122,8 @@ files:
122
122
  - gemfiles/active3.2.11.gemfile.lock
123
123
  - gemfiles/active4.0.0.gemfile
124
124
  - gemfiles/active4.0.0.gemfile.lock
125
+ - gemfiles/mongoid3.1.4.gemfile
126
+ - gemfiles/mongoid3.1.4.gemfile.lock
125
127
  - gemfiles/rails3.0.9.gemfile
126
128
  - gemfiles/rails3.0.9.gemfile.lock
127
129
  - gemfiles/rails3.1.1.gemfile
@@ -144,6 +146,7 @@ files:
144
146
  - spec/comma/comma_spec.rb
145
147
  - spec/comma/extractors_spec.rb
146
148
  - spec/comma/rails/active_record_spec.rb
149
+ - spec/comma/rails/mongoid_spec.rb
147
150
  - spec/controllers/users_controller_spec.rb
148
151
  - spec/non_rails_app/ruby_classes.rb
149
152
  - spec/rails_app/Rakefile
@@ -185,17 +188,17 @@ require_paths:
185
188
  - lib
186
189
  required_ruby_version: !ruby/object:Gem::Requirement
187
190
  requirements:
188
- - - '>='
191
+ - - ! '>='
189
192
  - !ruby/object:Gem::Version
190
193
  version: '0'
191
194
  required_rubygems_version: !ruby/object:Gem::Requirement
192
195
  requirements:
193
- - - '>='
196
+ - - ! '>='
194
197
  - !ruby/object:Gem::Version
195
198
  version: '0'
196
199
  requirements: []
197
200
  rubyforge_project: comma
198
- rubygems_version: 2.0.3
201
+ rubygems_version: 2.0.7
199
202
  signing_key:
200
203
  specification_version: 4
201
204
  summary: Ruby Comma Seperated Values generation library
@@ -203,6 +206,7 @@ test_files:
203
206
  - spec/comma/comma_spec.rb
204
207
  - spec/comma/extractors_spec.rb
205
208
  - spec/comma/rails/active_record_spec.rb
209
+ - spec/comma/rails/mongoid_spec.rb
206
210
  - spec/controllers/users_controller_spec.rb
207
211
  - spec/non_rails_app/ruby_classes.rb
208
212
  - spec/rails_app/Rakefile