active_report 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_report.rb +6 -6
- data/lib/active_report/array.rb +3 -5
- data/lib/active_report/hash.rb +4 -6
- data/lib/active_report/record.rb +7 -7
- data/lib/active_report/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebf90bb311957add7e00dc356a4155ab6d0eff5a
|
4
|
+
data.tar.gz: 4c85f87f49123255f67dae03405dd221cb40d8a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd84dc9f25ac4ec72ff2df3f40eaab3fbc9fc5cea8e75efd5d41bd19f56e873c3e28d0427286b56db00c8c7384c918d4cad70649ce491147f719dc2e80fba2af
|
7
|
+
data.tar.gz: e89cbb07d4bab09d75ed055c5f4e16ee9acd09a795d565bd5d10939e70206be140c4adea39230139458a2f333faff39f54ea354d22f3b71d7cf1ebac1531c219
|
data/lib/active_report.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require 'csv'
|
2
|
+
require 'active_object'
|
3
|
+
require 'active_report/version'
|
4
|
+
require 'active_report/array'
|
5
|
+
require 'active_report/hash'
|
6
|
+
require 'active_report/record'
|
data/lib/active_report/array.rb
CHANGED
@@ -21,16 +21,14 @@ class ActiveReport::Array
|
|
21
21
|
|
22
22
|
CSV.generate(@options) do |csv|
|
23
23
|
csv << @headers unless @headers.nil?
|
24
|
-
@datum.each { |
|
24
|
+
@datum.lazy.each { |d| csv << d }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def import
|
29
29
|
processed_datum = [].push(@headers).compact
|
30
|
-
CSV.foreach(@datum, @options)
|
31
|
-
|
32
|
-
end
|
33
|
-
return(processed_datum.size < 2 ? processed_datum.flatten : processed_datum)
|
30
|
+
CSV.foreach(@datum, @options) { |d| processed_datum.push(d) }
|
31
|
+
processed_datum.size < 2 ? processed_datum.flatten : processed_datum
|
34
32
|
end
|
35
33
|
|
36
34
|
end
|
data/lib/active_report/hash.rb
CHANGED
@@ -26,9 +26,9 @@ class ActiveReport::Hash
|
|
26
26
|
CSV.generate(@options) do |csv|
|
27
27
|
header = @datum.first.only(@only) unless @only.empty?
|
28
28
|
header = @datum.first.except(@except) unless @except.empty?
|
29
|
-
csv << (@headers || (header || @datum.first).keys.map { |k| k.to_s.gsub(
|
29
|
+
csv << (@headers || (header || @datum.first).keys.map { |k| k.to_s.gsub('_'.freeze, ' '.freeze).capitalize })
|
30
30
|
|
31
|
-
@datum.each do |data|
|
31
|
+
@datum.lazy.each do |data|
|
32
32
|
cell = data.only(@only) unless @only.empty?
|
33
33
|
cell = data.except(@except) unless @except.empty?
|
34
34
|
csv << (cell || data).values
|
@@ -41,14 +41,12 @@ class ActiveReport::Hash
|
|
41
41
|
@except = [].push(@except).compact unless @except.is_a?(Array)
|
42
42
|
|
43
43
|
processed_datum = []
|
44
|
-
CSV.foreach(@datum, @options).each_with_index do |data, line|
|
44
|
+
CSV.foreach(@datum, @options).lazy.each_with_index do |data, line|
|
45
45
|
if @headers.nil? && line.zero?
|
46
46
|
@headers = data
|
47
47
|
else
|
48
48
|
processed_data = {}
|
49
|
-
@headers.each_with_index
|
50
|
-
processed_data.store(v.to_s, data.fetch(i, nil) )
|
51
|
-
end
|
49
|
+
@headers.lazy.each_with_index { |v, i| processed_data.store(v.to_s, data.fetch(i, nil)) }
|
52
50
|
|
53
51
|
processed_data.only!(@only) unless @only.empty?
|
54
52
|
processed_data.except!(@except) unless @except.empty?
|
data/lib/active_report/record.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'json'
|
2
2
|
class ActiveReport::Record
|
3
3
|
|
4
4
|
attr_accessor :datum, :model, :only, :except, :headers, :options
|
@@ -28,9 +28,9 @@ class ActiveReport::Record
|
|
28
28
|
CSV.generate(@options) do |csv|
|
29
29
|
header = @datum.first.only(@only) unless @only.empty?
|
30
30
|
header = @datum.first.except(@except) unless @except.empty?
|
31
|
-
csv << (@headers || (header || @datum.first).keys.map { |k| k.to_s.gsub(
|
31
|
+
csv << (@headers || (header || @datum.first).keys.map { |k| k.to_s.gsub('_'.freeze, ' '.freeze).capitalize })
|
32
32
|
|
33
|
-
@datum.each do |data|
|
33
|
+
@datum.lazy.each do |data|
|
34
34
|
cell = data.only(@only) unless @only.empty?
|
35
35
|
cell = data.except(@except) unless @except.empty?
|
36
36
|
csv << (cell || data).values
|
@@ -41,19 +41,19 @@ class ActiveReport::Record
|
|
41
41
|
def import
|
42
42
|
if @model.nil? || (@model.superclass != ActiveRecord::Base)
|
43
43
|
raise ArgumentError,
|
44
|
-
"Model must be an ActiveRecord::Base object."
|
44
|
+
"Model must be an ActiveRecord::Base object.".freeze
|
45
45
|
end
|
46
46
|
|
47
47
|
@only = [].push(@only).compact unless @only.is_a?(Array)
|
48
48
|
@except = [].push(@except).compact unless @except.is_a?(Array)
|
49
49
|
|
50
50
|
@datum = ActiveReport::Hash.import(@datum, headers: @headers, options: @options)
|
51
|
-
@datum.each do |data|
|
52
|
-
data.transform_keys! { |k| k.to_s.downcase.gsub(
|
53
|
-
data.except!(:id)
|
51
|
+
@datum.lazy.each do |data|
|
52
|
+
data.transform_keys! { |k| k.to_s.downcase.gsub(' '.freeze, '_'.freeze).to_sym }
|
54
53
|
|
55
54
|
data.only!(@only) unless @only.empty?
|
56
55
|
data.except!(@except) unless @except.empty?
|
56
|
+
data.except!(:id)
|
57
57
|
|
58
58
|
@model.create(data)
|
59
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|