comma 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -1
  3. data/.rubocop_todo.yml +3 -364
  4. data/.travis.yml +36 -55
  5. data/Appraisals +14 -1
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +19 -16
  8. data/README.md +2 -2
  9. data/Rakefile +2 -0
  10. data/comma.gemspec +13 -11
  11. data/gemfiles/{active4.1.16.gemfile → active4.2.11.1.gemfile} +2 -2
  12. data/gemfiles/{active4.2.8.gemfile.lock → active4.2.11.1.gemfile.lock} +43 -38
  13. data/gemfiles/{active4.0.13.gemfile → active5.0.7.2.gemfile} +2 -2
  14. data/gemfiles/{active5.0.1.gemfile.lock → active5.0.7.2.gemfile.lock} +44 -40
  15. data/gemfiles/{active5.1.0.gemfile → active5.1.7.gemfile} +2 -2
  16. data/gemfiles/{active5.1.0.gemfile.lock → active5.1.7.gemfile.lock} +44 -40
  17. data/gemfiles/{active4.2.8.gemfile → active5.2.3.gemfile} +2 -2
  18. data/gemfiles/active5.2.3.gemfile.lock +108 -0
  19. data/gemfiles/{active5.0.1.gemfile → active6.0.0.gemfile} +2 -2
  20. data/gemfiles/{active5.2.0.gemfile.lock → active6.0.0.gemfile.lock} +31 -29
  21. data/gemfiles/{rails4.1.16.gemfile → rails4.2.11.1.gemfile} +1 -1
  22. data/gemfiles/{rails4.2.8.gemfile.lock → rails4.2.11.1.gemfile.lock} +84 -80
  23. data/gemfiles/{rails4.0.13.gemfile → rails5.0.7.2.gemfile} +1 -1
  24. data/gemfiles/rails5.0.7.2.gemfile.lock +198 -0
  25. data/gemfiles/{rails5.1.0.gemfile → rails5.1.7.gemfile} +1 -1
  26. data/gemfiles/rails5.1.7.gemfile.lock +198 -0
  27. data/gemfiles/{rails5.2.0.gemfile → rails5.2.3.gemfile} +1 -1
  28. data/gemfiles/{rails5.2.0.gemfile.lock → rails5.2.3.gemfile.lock} +82 -80
  29. data/gemfiles/{rails4.2.8.gemfile → rails6.0.0.gemfile} +1 -1
  30. data/gemfiles/rails6.0.0.gemfile.lock +237 -0
  31. data/init.rb +2 -0
  32. data/lib/comma.rb +23 -33
  33. data/lib/comma/array.rb +2 -0
  34. data/lib/comma/data_extractor.rb +5 -5
  35. data/lib/comma/data_mapper_collection.rb +9 -3
  36. data/lib/comma/extractor.rb +3 -5
  37. data/lib/comma/generator.rb +11 -11
  38. data/lib/comma/header_extractor.rb +18 -14
  39. data/lib/comma/mongoid.rb +10 -7
  40. data/lib/comma/object.rb +5 -1
  41. data/lib/comma/relation.rb +16 -10
  42. data/lib/comma/version.rb +3 -1
  43. data/spec/comma/comma_spec.rb +68 -47
  44. data/spec/comma/data_extractor_spec.rb +6 -10
  45. data/spec/comma/header_extractor_spec.rb +2 -8
  46. data/spec/comma/rails/active_record_spec.rb +28 -26
  47. data/spec/comma/rails/data_mapper_collection_spec.rb +4 -3
  48. data/spec/comma/rails/mongoid_spec.rb +8 -7
  49. data/spec/controllers/users_controller_spec.rb +48 -47
  50. data/spec/non_rails_app/ruby_classes.rb +13 -6
  51. data/spec/rails_app/active_record/config.rb +3 -1
  52. data/spec/rails_app/active_record/models.rb +4 -2
  53. data/spec/rails_app/data_mapper/config.rb +2 -0
  54. data/spec/rails_app/mongoid/config.rb +4 -2
  55. data/spec/rails_app/rails_app.rb +12 -11
  56. data/spec/rails_app/tmp/.gitkeep +0 -0
  57. data/spec/spec_helper.rb +7 -3
  58. metadata +27 -30
  59. data/gemfiles/active4.0.13.gemfile.lock +0 -107
  60. data/gemfiles/active4.1.16.gemfile.lock +0 -106
  61. data/gemfiles/active5.2.0.gemfile +0 -10
  62. data/gemfiles/rails4.0.13.gemfile.lock +0 -158
  63. data/gemfiles/rails4.1.16.gemfile.lock +0 -162
  64. data/gemfiles/rails5.0.1.gemfile +0 -11
  65. data/gemfiles/rails5.0.1.gemfile.lock +0 -194
  66. data/gemfiles/rails5.1.0.gemfile.lock +0 -194
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "coveralls", :require => false
6
6
  gem "rubocop", :require => false
7
- gem "rails", "4.2.8"
7
+ gem "rails", "6.0.0.beta3"
8
8
  gem "rspec-rails"
9
9
  gem "test-unit"
10
10
 
@@ -0,0 +1,237 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ comma (4.3.0)
5
+ activesupport (>= 4.0.0, < 6.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.0.0.beta3)
11
+ actionpack (= 6.0.0.beta3)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailbox (6.0.0.beta3)
15
+ actionpack (= 6.0.0.beta3)
16
+ activejob (= 6.0.0.beta3)
17
+ activerecord (= 6.0.0.beta3)
18
+ activestorage (= 6.0.0.beta3)
19
+ activesupport (= 6.0.0.beta3)
20
+ mail (>= 2.7.1)
21
+ actionmailer (6.0.0.beta3)
22
+ actionpack (= 6.0.0.beta3)
23
+ actionview (= 6.0.0.beta3)
24
+ activejob (= 6.0.0.beta3)
25
+ mail (~> 2.5, >= 2.5.4)
26
+ rails-dom-testing (~> 2.0)
27
+ actionpack (6.0.0.beta3)
28
+ actionview (= 6.0.0.beta3)
29
+ activesupport (= 6.0.0.beta3)
30
+ rack (~> 2.0)
31
+ rack-test (>= 0.6.3)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
34
+ actiontext (6.0.0.beta3)
35
+ actionpack (= 6.0.0.beta3)
36
+ activerecord (= 6.0.0.beta3)
37
+ activestorage (= 6.0.0.beta3)
38
+ activesupport (= 6.0.0.beta3)
39
+ nokogiri (>= 1.8.5)
40
+ actionview (6.0.0.beta3)
41
+ activesupport (= 6.0.0.beta3)
42
+ builder (~> 3.1)
43
+ erubi (~> 1.4)
44
+ rails-dom-testing (~> 2.0)
45
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
46
+ activejob (6.0.0.beta3)
47
+ activesupport (= 6.0.0.beta3)
48
+ globalid (>= 0.3.6)
49
+ activemodel (6.0.0.beta3)
50
+ activesupport (= 6.0.0.beta3)
51
+ activerecord (6.0.0.beta3)
52
+ activemodel (= 6.0.0.beta3)
53
+ activesupport (= 6.0.0.beta3)
54
+ activestorage (6.0.0.beta3)
55
+ actionpack (= 6.0.0.beta3)
56
+ activerecord (= 6.0.0.beta3)
57
+ marcel (~> 0.3.1)
58
+ activesupport (6.0.0.beta3)
59
+ concurrent-ruby (~> 1.0, >= 1.0.2)
60
+ i18n (>= 0.7, < 2)
61
+ minitest (~> 5.1)
62
+ tzinfo (~> 1.1)
63
+ zeitwerk (~> 1.3, >= 1.3.1)
64
+ appraisal (1.0.3)
65
+ bundler
66
+ rake
67
+ thor (>= 0.14.0)
68
+ ast (2.4.0)
69
+ builder (3.2.3)
70
+ concurrent-ruby (1.1.5)
71
+ coveralls (0.7.1)
72
+ multi_json (~> 1.3)
73
+ rest-client
74
+ simplecov (>= 0.7)
75
+ term-ansicolor
76
+ thor
77
+ crass (1.0.4)
78
+ diff-lcs (1.3)
79
+ docile (1.3.1)
80
+ domain_name (0.5.20180417)
81
+ unf (>= 0.0.5, < 1.0.0)
82
+ erubi (1.8.0)
83
+ globalid (0.4.2)
84
+ activesupport (>= 4.2.0)
85
+ http-cookie (1.0.3)
86
+ domain_name (~> 0.5)
87
+ i18n (1.6.0)
88
+ concurrent-ruby (~> 1.0)
89
+ jaro_winkler (1.5.2)
90
+ json (2.2.0)
91
+ loofah (2.2.3)
92
+ crass (~> 1.0.2)
93
+ nokogiri (>= 1.5.9)
94
+ mail (2.7.1)
95
+ mini_mime (>= 0.1.1)
96
+ marcel (0.3.3)
97
+ mimemagic (~> 0.3.2)
98
+ method_source (0.9.2)
99
+ mime-types (3.2.2)
100
+ mime-types-data (~> 3.2015)
101
+ mime-types-data (3.2019.0331)
102
+ mimemagic (0.3.3)
103
+ mini_mime (1.0.1)
104
+ mini_portile2 (2.4.0)
105
+ minitest (5.11.3)
106
+ multi_json (1.13.1)
107
+ netrc (0.11.0)
108
+ nio4r (2.3.1)
109
+ nokogiri (1.10.2)
110
+ mini_portile2 (~> 2.4.0)
111
+ parallel (1.17.0)
112
+ parser (2.6.2.1)
113
+ ast (~> 2.4.0)
114
+ power_assert (1.1.4)
115
+ psych (3.1.0)
116
+ rack (2.0.7)
117
+ rack-test (1.1.0)
118
+ rack (>= 1.0, < 3)
119
+ rails (6.0.0.beta3)
120
+ actioncable (= 6.0.0.beta3)
121
+ actionmailbox (= 6.0.0.beta3)
122
+ actionmailer (= 6.0.0.beta3)
123
+ actionpack (= 6.0.0.beta3)
124
+ actiontext (= 6.0.0.beta3)
125
+ actionview (= 6.0.0.beta3)
126
+ activejob (= 6.0.0.beta3)
127
+ activemodel (= 6.0.0.beta3)
128
+ activerecord (= 6.0.0.beta3)
129
+ activestorage (= 6.0.0.beta3)
130
+ activesupport (= 6.0.0.beta3)
131
+ bundler (>= 1.3.0)
132
+ railties (= 6.0.0.beta3)
133
+ sprockets-rails (>= 2.0.0)
134
+ rails-dom-testing (2.0.3)
135
+ activesupport (>= 4.2.0)
136
+ nokogiri (>= 1.6)
137
+ rails-html-sanitizer (1.0.4)
138
+ loofah (~> 2.2, >= 2.2.2)
139
+ railties (6.0.0.beta3)
140
+ actionpack (= 6.0.0.beta3)
141
+ activesupport (= 6.0.0.beta3)
142
+ method_source
143
+ rake (>= 0.8.7)
144
+ thor (>= 0.20.3, < 2.0)
145
+ rainbow (3.0.0)
146
+ rake (10.5.0)
147
+ rest-client (2.0.2)
148
+ http-cookie (>= 1.0.2, < 2.0)
149
+ mime-types (>= 1.16, < 4.0)
150
+ netrc (~> 0.8)
151
+ rspec (3.5.0)
152
+ rspec-core (~> 3.5.0)
153
+ rspec-expectations (~> 3.5.0)
154
+ rspec-mocks (~> 3.5.0)
155
+ rspec-activemodel-mocks (1.1.0)
156
+ activemodel (>= 3.0)
157
+ activesupport (>= 3.0)
158
+ rspec-mocks (>= 2.99, < 4.0)
159
+ rspec-core (3.5.4)
160
+ rspec-support (~> 3.5.0)
161
+ rspec-expectations (3.5.0)
162
+ diff-lcs (>= 1.2.0, < 2.0)
163
+ rspec-support (~> 3.5.0)
164
+ rspec-its (1.3.0)
165
+ rspec-core (>= 3.0.0)
166
+ rspec-expectations (>= 3.0.0)
167
+ rspec-mocks (3.5.0)
168
+ diff-lcs (>= 1.2.0, < 2.0)
169
+ rspec-support (~> 3.5.0)
170
+ rspec-rails (3.5.2)
171
+ actionpack (>= 3.0)
172
+ activesupport (>= 3.0)
173
+ railties (>= 3.0)
174
+ rspec-core (~> 3.5.0)
175
+ rspec-expectations (~> 3.5.0)
176
+ rspec-mocks (~> 3.5.0)
177
+ rspec-support (~> 3.5.0)
178
+ rspec-support (3.5.0)
179
+ rubocop (0.67.2)
180
+ jaro_winkler (~> 1.5.1)
181
+ parallel (~> 1.10)
182
+ parser (>= 2.5, != 2.5.1.1)
183
+ psych (>= 3.1.0)
184
+ rainbow (>= 2.2.2, < 4.0)
185
+ ruby-progressbar (~> 1.7)
186
+ unicode-display_width (>= 1.4.0, < 1.6)
187
+ ruby-progressbar (1.10.0)
188
+ simplecov (0.16.1)
189
+ docile (~> 1.1)
190
+ json (>= 1.8, < 3)
191
+ simplecov-html (~> 0.10.0)
192
+ simplecov-html (0.10.2)
193
+ sprockets (3.7.2)
194
+ concurrent-ruby (~> 1.0)
195
+ rack (> 1, < 3)
196
+ sprockets-rails (3.2.1)
197
+ actionpack (>= 4.0)
198
+ activesupport (>= 4.0)
199
+ sprockets (>= 3.0.0)
200
+ sqlite3 (1.3.13)
201
+ term-ansicolor (1.7.1)
202
+ tins (~> 1.0)
203
+ test-unit (3.3.2)
204
+ power_assert
205
+ thor (0.20.3)
206
+ thread_safe (0.3.6)
207
+ tins (1.20.2)
208
+ tzinfo (1.2.5)
209
+ thread_safe (~> 0.1)
210
+ unf (0.1.4)
211
+ unf_ext
212
+ unf_ext (0.0.7.5)
213
+ unicode-display_width (1.5.0)
214
+ websocket-driver (0.7.0)
215
+ websocket-extensions (>= 0.1.0)
216
+ websocket-extensions (0.1.3)
217
+ zeitwerk (1.4.3)
218
+
219
+ PLATFORMS
220
+ ruby
221
+
222
+ DEPENDENCIES
223
+ appraisal (~> 1.0.0)
224
+ comma!
225
+ coveralls
226
+ rails (= 6.0.0.beta3)
227
+ rake (~> 10.5.0)
228
+ rspec (~> 3.5.0)
229
+ rspec-activemodel-mocks
230
+ rspec-its
231
+ rspec-rails
232
+ rubocop
233
+ sqlite3 (~> 1.3.11)
234
+ test-unit
235
+
236
+ BUNDLED WITH
237
+ 1.17.3
data/init.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'comma'
data/lib/comma.rb CHANGED
@@ -1,26 +1,13 @@
1
- # load the right csv library
2
- if RUBY_VERSION >= '1.9'
3
- require 'csv'
4
- CSV_HANDLER = CSV
5
- else
6
- begin
7
- gem 'fastercsv'
8
- require 'fastercsv'
1
+ # frozen_string_literal: true
9
2
 
10
- CSV_HANDLER = FasterCSV
11
- rescue LoadError => e
12
- raise "Error : FasterCSV not installed, please `gem install fastercsv` for faster processing on <Ruby 1.9"
13
- end
14
- end
15
-
16
- raise "Error - This Comma version only supports Rails 3.x. Please use a 2.x version of Comma for use with earlier rails versions." if
17
- defined? Rails and (Rails.version.split('.').map(&:to_i).first < 3)
3
+ require 'csv'
4
+ CSV_HANDLER = CSV
18
5
 
19
6
  module Comma
20
7
  DEFAULT_OPTIONS = {
21
- :write_headers => true,
22
- :style => :default
23
- }
8
+ write_headers: true,
9
+ style: :default
10
+ }.freeze
24
11
  end
25
12
 
26
13
  require 'active_support/lazy_load_hooks'
@@ -38,30 +25,33 @@ require 'comma/generator'
38
25
  require 'comma/array'
39
26
  require 'comma/object'
40
27
 
41
- #Load into Rails controllers
28
+ # Load into Rails controllers
42
29
  ActiveSupport.on_load(:action_controller) do
43
30
  if defined?(ActionController::Renderers) && ActionController::Renderers.respond_to?(:add)
44
31
  ActionController::Renderers.add :csv do |obj, options|
45
32
  filename = options[:filename] || 'data'
46
33
  extension = options[:extension] || 'csv'
47
34
 
48
- if Rails.version >= "5.0.0"
49
- mime_type = options[:mime_type] || Mime[:csv]
50
- else
51
- mime_type = options[:mime_type] || Mime::CSV
52
- end
35
+ mime_type = if Rails.version >= '5.0.0'
36
+ options[:mime_type] || Mime[:csv]
37
+ else
38
+ options[:mime_type] || Mime::CSV
39
+ end
53
40
 
54
- #Capture any CSV optional settings passed to comma or comma specific options
55
- csv_options = options.slice(*CSV_HANDLER::DEFAULT_OPTIONS.merge(Comma::DEFAULT_OPTIONS).keys).each_with_object({}) do |(k, v), h|
41
+ # Capture any CSV optional settings passed to comma or comma specific options
42
+ csv_options = options.slice(*CSV_HANDLER::DEFAULT_OPTIONS.merge(Comma::DEFAULT_OPTIONS).keys)
43
+ csv_options = csv_options.each_with_object({}) do |(k, v), h|
56
44
  # XXX: Convert string to boolean
57
45
  h[k] = case k
58
- when :write_headers
59
- v = (v != 'false') if v.is_a?(String)
60
- else
61
- v
62
- end
46
+ when :write_headers
47
+ (v != 'false') if v.is_a?(String)
48
+ else
49
+ v
50
+ end
63
51
  end
64
- send_data obj.to_comma(csv_options), :type => mime_type, :disposition => "attachment; filename=\"#{filename}.#{extension}\""
52
+ data = obj.to_comma(csv_options)
53
+ disposition = "attachment; filename=\"#{filename}.#{extension}\""
54
+ send_data data, type: mime_type, disposition: disposition
65
55
  end
66
56
  end
67
57
  end
data/lib/comma/array.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Array
2
4
  def to_comma(style = :default)
3
5
  Comma::Generator.new(self, style).run(:each)
@@ -1,9 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'comma/extractor'
2
4
 
3
5
  module Comma
4
-
5
6
  class DataExtractor < Extractor
6
-
7
7
  class ExtractValueFromInstance
8
8
  def initialize(instance)
9
9
  @instance = instance
@@ -42,7 +42,7 @@ module Comma
42
42
 
43
43
  def null_association
44
44
  @null_association ||= Class.new(Class.const_defined?(:BasicObject) ? ::BasicObject : ::Object) do
45
- def method_missing(symbol, *args, &block)
45
+ def method_missing(_symbol, *_args, &_block)
46
46
  nil
47
47
  end
48
48
  end.new
@@ -56,7 +56,7 @@ module Comma
56
56
  args.each do |arg|
57
57
  case arg
58
58
  when Hash
59
- arg.each do |k, v|
59
+ arg.each do |k, _v|
60
60
  @results << ExtractValueFromAssociationOfInstance.new(@instance, sym).extract(k, &block)
61
61
  end
62
62
  when Symbol
@@ -69,7 +69,7 @@ module Comma
69
69
  end
70
70
  end
71
71
 
72
- def __static_column__(header = nil, &block)
72
+ def __static_column__(_header = nil, &block)
73
73
  @results << (block ? yield(@instance) : nil)
74
74
  end
75
75
  end
@@ -1,5 +1,11 @@
1
- class DataMapper::Collection
2
- def to_comma(style = :default)
3
- Comma::Generator.new(self, style).run(:each)
1
+ # frozen_string_literal: true
2
+
3
+ if defined?(DataMapper)
4
+ module DataMapper
5
+ class Collection
6
+ def to_comma(style = :default)
7
+ Comma::Generator.new(self, style).run(:each)
8
+ end
9
+ end
4
10
  end
5
11
  end
@@ -1,7 +1,7 @@
1
- module Comma
1
+ # frozen_string_literal: true
2
2
 
3
+ module Comma
3
4
  class Extractor
4
-
5
5
  def initialize(instance, style, formats)
6
6
  @instance = instance
7
7
  @style = style
@@ -10,7 +10,7 @@ module Comma
10
10
  end
11
11
 
12
12
  def results
13
- instance_eval &@formats[@style]
13
+ instance_eval(&@formats[@style])
14
14
  @results.map { |r| convert_to_data_value(r) }
15
15
  end
16
16
 
@@ -28,7 +28,5 @@ module Comma
28
28
  def convert_to_data_value(result)
29
29
  result.nil? ? result : result.to_s
30
30
  end
31
-
32
31
  end
33
-
34
32
  end
@@ -1,24 +1,24 @@
1
- module Comma
1
+ # frozen_string_literal: true
2
2
 
3
+ module Comma
3
4
  class Generator
4
-
5
5
  def initialize(instance, style)
6
6
  @instance = instance
7
7
  @style = style
8
8
  @options = {}
9
9
 
10
- if @style.is_a? Hash
11
- @options = @style.clone
12
- @style = @options.delete(:style) || Comma::DEFAULT_OPTIONS[:style]
13
- @filename = @options.delete(:filename)
14
- end
10
+ return unless @style.is_a?(Hash)
11
+
12
+ @options = @style.clone
13
+ @style = @options.delete(:style) || Comma::DEFAULT_OPTIONS[:style]
14
+ @filename = @options.delete(:filename)
15
15
  end
16
16
 
17
17
  def run(iterator_method)
18
18
  if @filename
19
- CSV_HANDLER.open(@filename, 'w', @options){ |csv| append_csv(csv, iterator_method) } and return true
19
+ CSV_HANDLER.open(@filename, 'w', @options) { |csv| append_csv(csv, iterator_method) } && (return true)
20
20
  else
21
- CSV_HANDLER.generate(@options){ |csv| append_csv(csv, iterator_method) }
21
+ CSV_HANDLER.generate(@options) { |csv| append_csv(csv, iterator_method) }
22
22
  end
23
23
  end
24
24
 
@@ -26,12 +26,12 @@ module Comma
26
26
 
27
27
  def append_csv(csv, iterator_method)
28
28
  return '' if @instance.empty?
29
+
29
30
  csv << @instance.first.to_comma_headers(@style) unless
30
- @options.has_key?(:write_headers) && !@options[:write_headers]
31
+ @options.key?(:write_headers) && !@options[:write_headers]
31
32
  @instance.send(iterator_method) do |object|
32
33
  csv << object.to_comma(@style)
33
34
  end
34
35
  end
35
-
36
36
  end
37
37
  end