comma-heaven 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -11,4 +11,5 @@ group :development do
11
11
  gem "jeweler", "~> 1.8.3"
12
12
  gem 'simplecov', :require => false
13
13
  gem 'sqlite3'
14
+ gem 'mysql2', '0.2.7'
14
15
  end
data/Gemfile.lock CHANGED
@@ -9,30 +9,31 @@ GEM
9
9
  activesupport (2.3.14)
10
10
  diff-lcs (1.1.3)
11
11
  git (1.2.5)
12
- jeweler (1.8.3)
12
+ jeweler (1.8.4)
13
13
  bundler (~> 1.0)
14
14
  git (>= 1.2.5)
15
15
  rake
16
16
  rdoc
17
- json (1.6.6)
18
- multi_json (1.3.1)
19
- rack (1.1.2)
17
+ json (1.7.5)
18
+ multi_json (1.3.6)
19
+ mysql2 (0.2.7)
20
+ rack (1.1.3)
20
21
  rake (0.9.2.2)
21
22
  rdoc (3.12)
22
23
  json (~> 1.4)
23
- rspec (2.9.0)
24
- rspec-core (~> 2.9.0)
25
- rspec-expectations (~> 2.9.0)
26
- rspec-mocks (~> 2.9.0)
27
- rspec-core (2.9.0)
28
- rspec-expectations (2.9.1)
24
+ rspec (2.11.0)
25
+ rspec-core (~> 2.11.0)
26
+ rspec-expectations (~> 2.11.0)
27
+ rspec-mocks (~> 2.11.0)
28
+ rspec-core (2.11.1)
29
+ rspec-expectations (2.11.3)
29
30
  diff-lcs (~> 1.1.3)
30
- rspec-mocks (2.9.0)
31
- simplecov (0.6.1)
31
+ rspec-mocks (2.11.3)
32
+ simplecov (0.7.1)
32
33
  multi_json (~> 1.0)
33
- simplecov-html (~> 0.5.3)
34
- simplecov-html (0.5.3)
35
- sqlite3 (1.3.5)
34
+ simplecov-html (~> 0.7.1)
35
+ simplecov-html (0.7.1)
36
+ sqlite3 (1.3.6)
36
37
 
37
38
  PLATFORMS
38
39
  ruby
@@ -42,6 +43,7 @@ DEPENDENCIES
42
43
  activerecord (< 3.0.0)
43
44
  bundler (>= 1.0.0)
44
45
  jeweler (~> 1.8.3)
46
+ mysql2 (= 0.2.7)
45
47
  rdoc (~> 3.12)
46
48
  rspec (>= 1.2.9)
47
49
  simplecov
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.3
data/comma-heaven.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "comma-heaven"
8
- s.version = "0.7.2"
8
+ s.version = "0.7.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Silvano Stralla"]
12
- s.date = "2012-10-20"
12
+ s.date = "2012-10-22"
13
13
  s.description = "CommaHeaven permits easy exports of Rails models to CSV"
14
14
  s.email = "silvano.stralla@sistrall.it"
15
15
  s.extra_rdoc_files = [
@@ -64,6 +64,7 @@ Gem::Specification.new do |s|
64
64
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
65
65
  s.add_development_dependency(%q<simplecov>, [">= 0"])
66
66
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
67
+ s.add_development_dependency(%q<mysql2>, ["= 0.2.7"])
67
68
  else
68
69
  s.add_dependency(%q<activerecord>, ["< 3.0.0"])
69
70
  s.add_dependency(%q<actionpack>, ["< 3.0.0"])
@@ -73,6 +74,7 @@ Gem::Specification.new do |s|
73
74
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
74
75
  s.add_dependency(%q<simplecov>, [">= 0"])
75
76
  s.add_dependency(%q<sqlite3>, [">= 0"])
77
+ s.add_dependency(%q<mysql2>, ["= 0.2.7"])
76
78
  end
77
79
  else
78
80
  s.add_dependency(%q<activerecord>, ["< 3.0.0"])
@@ -83,6 +85,7 @@ Gem::Specification.new do |s|
83
85
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
84
86
  s.add_dependency(%q<simplecov>, [">= 0"])
85
87
  s.add_dependency(%q<sqlite3>, [">= 0"])
88
+ s.add_dependency(%q<mysql2>, ["= 0.2.7"])
86
89
  end
87
90
  end
88
91
 
@@ -19,22 +19,26 @@ module CommaHeaven
19
19
  FasterCSV::Table.new([]).tap do |table|
20
20
  columns = CommaHeaven::Sqler::Columns.new(self, options[:export])
21
21
  headers = columns.sql_as
22
+
23
+ ids = find(:all, :select => "#{table_name}.#{primary_key}", :limit => options[:limit]).map(&:id)
22
24
 
23
- find(:all, :limit => options[:limit], :joins => columns.joins, :select => columns.select).each do |resource|
24
- fields = columns.sql_as.inject([]) do |acc, field|
25
- value = resource.send(field)
26
-
27
- if options[:format]
28
- begin
29
- value = value.to_time.strftime(options[:format][:datetime]) if value =~ %r{^(\d{4,4})-(\d{2,2})-(\d{2,2})} && options[:format][:datetime]
30
- rescue
25
+ with_exclusive_scope do
26
+ find(:all, :conditions => ["#{columns.table_alias}.#{primary_key} IN (?)", ids], :limit => options[:limit], :joins => columns.joins, :select => columns.select).each do |resource|
27
+ fields = columns.sql_as.inject([]) do |acc, field|
28
+ value = resource.send(field)
29
+
30
+ if options[:format]
31
+ begin
32
+ value = value.to_time.strftime(options[:format][:datetime]) if value =~ %r{^(\d{4,4})-(\d{2,2})-(\d{2,2})} && options[:format][:datetime]
33
+ rescue
34
+ end
31
35
  end
36
+
37
+ acc << options[:converter].call(value)
32
38
  end
33
39
 
34
- acc << options[:converter].call(value)
40
+ table << FasterCSV::Row.new(headers, fields)
35
41
  end
36
-
37
- table << FasterCSV::Row.new(headers, fields)
38
42
  end
39
43
  end
40
44
  end
@@ -31,8 +31,7 @@ module CommaHeaven
31
31
  csv_options = all_options.slice(*FasterCSV::DEFAULT_OPTIONS.keys)
32
32
  tch_options = all_options.except(*FasterCSV::DEFAULT_OPTIONS.keys) # TCH means To Comma Heaven
33
33
 
34
- ids = klass.scoped(current_scope).find(:all, :select => "#{klass.table_name}.#{klass.primary_key}").map(&:id)
35
- klass.scoped(:conditions => ['id IN (?)', ids]).to_comma_heaven(tch_options.symbolize_keys).to_csv(csv_options.symbolize_keys)
34
+ klass.scoped(current_scope).to_comma_heaven(tch_options.symbolize_keys).to_csv(csv_options.symbolize_keys)
36
35
  end
37
36
 
38
37
  private
data/spec/export_spec.rb CHANGED
@@ -41,6 +41,11 @@ describe "Export" do
41
41
  Tree.to_comma_heaven(:export => {:name => {0 => {}}, :age => {1 => {}}}).to_csv
42
42
  end
43
43
 
44
+ it "should export scoped model" do
45
+ Tree.scoped(:conditions => {:name => 'Ulivo'}).export(@params).save.should ==
46
+ Tree.scoped(:conditions => {:name => 'Ulivo'}).to_comma_heaven(@params).to_csv
47
+ end
48
+
44
49
  it "should export to CSV using customized options made available through FasterCSV" do
45
50
  Tree.export(:export => {:name => {0 => {}}, :age => {1 => {}}}, :col_sep => ";", :force_quotes => true).save.should ==
46
51
  Tree.to_comma_heaven(:export => {:name => {0 => {}}, :age => {1 => {}}}).to_csv(:col_sep => ";", :force_quotes => true)
data/spec/spec_helper.rb CHANGED
@@ -11,44 +11,49 @@ ENV['TZ'] = 'UTC'
11
11
  Time.zone = 'Eastern Time (US & Canada)'
12
12
 
13
13
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
14
+ # ActiveRecord::Base.establish_connection(:adapter => "mysql2", :database => "comma-heaven-test", :user => 'root', :password => '')
14
15
  ActiveRecord::Base.configurations = true
16
+ # ActiveRecord::Base.logger = Logger.new(STDOUT)
15
17
 
16
18
  ActiveRecord::Schema.verbose = false
17
- ActiveRecord::Schema.define(:version => 1) do
18
- create_table :gardeners do |t|
19
- t.string :name
20
- t.string :surname
21
- t.datetime :birthdate
22
- end
23
-
24
- create_table :gardener_clones do |t|
25
- t.integer :gardener_id
26
- t.string :name
27
- t.string :surname
28
- end
29
-
30
- create_table :trees do |t|
31
- t.string :name
32
- t.integer :age
33
- t.integer :gardener_id
34
- end
35
-
36
- create_table :leafs do |t|
37
- t.integer :tree_id
38
- t.string :position
39
- t.float :size
40
- t.float :height_from_ground
41
- end
42
-
43
- create_table :cells do |t|
44
- t.integer :leaf_id
45
- t.float :weight
46
- t.float :lat
47
- t.float :lng
48
- end
49
- end
50
19
 
51
20
  RSpec.configure do |config|
21
+ config.before(:all) do
22
+ ActiveRecord::Schema.define(:version => 1) do
23
+ create_table :gardeners do |t|
24
+ t.string :name
25
+ t.string :surname
26
+ t.datetime :birthdate
27
+ end
28
+
29
+ create_table :gardener_clones do |t|
30
+ t.integer :gardener_id
31
+ t.string :name
32
+ t.string :surname
33
+ end
34
+
35
+ create_table :trees do |t|
36
+ t.string :name
37
+ t.integer :age
38
+ t.integer :gardener_id
39
+ end
40
+
41
+ create_table :leafs do |t|
42
+ t.integer :tree_id
43
+ t.string :position
44
+ t.float :size
45
+ t.float :height_from_ground
46
+ end
47
+
48
+ create_table :cells do |t|
49
+ t.integer :leaf_id
50
+ t.float :weight
51
+ t.float :lat
52
+ t.float :lng
53
+ end
54
+ end
55
+ end
56
+
52
57
  config.before(:each) do
53
58
  class Gardener < ActiveRecord::Base
54
59
  has_many :trees
@@ -90,4 +95,14 @@ RSpec.configure do |config|
90
95
  Object.send(:remove_const, :Leaf)
91
96
  Object.send(:remove_const, :Cell)
92
97
  end
98
+
99
+ config.after(:all) do
100
+ ActiveRecord::Schema.define(:version => 2) do
101
+ drop_table :gardeners
102
+ drop_table :gardener_clones
103
+ drop_table :trees
104
+ drop_table :leafs
105
+ drop_table :cells
106
+ end
107
+ end
93
108
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: comma-heaven
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.2
5
+ version: 0.7.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Silvano Stralla
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-10-20 00:00:00 Z
13
+ date: 2012-10-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -100,6 +100,17 @@ dependencies:
100
100
  type: :development
101
101
  prerelease: false
102
102
  version_requirements: *id008
103
+ - !ruby/object:Gem::Dependency
104
+ name: mysql2
105
+ requirement: &id009 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - "="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.2.7
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: *id009
103
114
  description: CommaHeaven permits easy exports of Rails models to CSV
104
115
  email: silvano.stralla@sistrall.it
105
116
  executables: []
@@ -151,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
162
  requirements:
152
163
  - - ">="
153
164
  - !ruby/object:Gem::Version
154
- hash: 2387181132478427829
165
+ hash: 2399762168738389712
155
166
  segments:
156
167
  - 0
157
168
  version: "0"