active_report 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1400a2e55695801ae3744d763719f7f12f27e74d
4
- data.tar.gz: e5ccf603982e504bf4fd5f35f026664a798e6d77
3
+ metadata.gz: b787a1e917a1f343bac52cd6e96ef35dbbf0c32a
4
+ data.tar.gz: cdefb7be0ef01b92a85b1994d3d331d3c3e219b8
5
5
  SHA512:
6
- metadata.gz: 309b56bb9dfa90def2489429a9f22d5e9bea72abc5094c8a6daeffacd55106b2cb7983d581e4b78cf3a0b53c0bad90a2b184c86abf67367a75ede8e87880e55a
7
- data.tar.gz: 6c64e77f92103be44c2f9157699ce00433df1db28bb8a132a85e751c43883b041149505954f7a7e599daa41384e40c2902716b98db37cc8205db9da7ffe44675
6
+ metadata.gz: 4a0dc434e18b8d9e53be40873075675088b6c4fb02ab3cc21878e2b14bb07abbd05498ddeaa85cd8786c1286418225b0b0052aff941b363d351db09559f2b620
7
+ data.tar.gz: e30a08a67494a1c7233ed642ff024b11efd2e177ed26535f8ecfaef8cce6ddc9a7a38f156502557295d252ddbc02b8ccb463fc53d23e19156a111094bea89a59
data/README.md CHANGED
@@ -123,8 +123,8 @@ ActiveReport::Record.export(@list, only: [:id, :item], headers: ["ID", "Task"],
123
123
  * options: CSV options to be use on parsing
124
124
 
125
125
  ```ruby
126
- ActiveReport::Record.import("sample.csv", User)
127
- ActiveReport::Record.import("sample.csv", User, except: :completed, headers: ["ID", "Task"], options: { col_sep: ";" })
126
+ ActiveReport::Record.import("sample.csv", model: User)
127
+ ActiveReport::Record.import("sample.csv", model: User, except: :completed, headers: ["ID", "Task"], options: { col_sep: ";" })
128
128
  ```
129
129
 
130
130
  ## Contributing
@@ -19,8 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_runtime_dependency "activerecord"
23
+ spec.add_runtime_dependency "activesupport"
24
+ spec.add_runtime_dependency "active_object"
25
+
22
26
  spec.add_development_dependency "bundler"
23
27
  spec.add_development_dependency "coveralls"
24
28
  spec.add_development_dependency "rake"
25
29
  spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "sqlite3"
31
+ spec.add_development_dependency "database_cleaner"
26
32
  end
data/lib/active_report.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "csv"
2
+ require "active_object"
2
3
  require "active_report/version"
3
4
  require "active_report/array"
4
5
  require "active_report/hash"
@@ -30,7 +30,7 @@ class ActiveReport::Array
30
30
  CSV.foreach(@datum, @options) do |data|
31
31
  processed_datum.push(data)
32
32
  end
33
- return(processed_datum.count < 2 ? processed_datum.flatten : processed_datum)
33
+ return(processed_datum.size < 2 ? processed_datum.flatten : processed_datum)
34
34
  end
35
35
 
36
36
  end
@@ -24,13 +24,13 @@ class ActiveReport::Hash
24
24
  @except = [].push(@except).compact unless @except.is_a?(Array)
25
25
 
26
26
  CSV.generate(@options) do |csv|
27
- header = @datum.first.dup.keep_if { |k,v| @only.include?(k) } unless @only.empty?
28
- header = @datum.first.dup.delete_if { |k,v| @except.include?(k) } unless @except.empty?
29
- csv << (@headers || (header || @datum.first).keys.map { |k| k.to_s.gsub("_", " ").capitalize})
27
+ header = @datum.first.only(@only) unless @only.empty?
28
+ header = @datum.first.except(@except) unless @except.empty?
29
+ csv << (@headers || (header || @datum.first).keys.map { |k| k.to_s.gsub("_", " ").capitalize })
30
30
 
31
31
  @datum.each do |data|
32
- cell = data.dup.keep_if { |k,v| @only.include?(k) } unless @only.empty?
33
- cell = data.dup.delete_if { |k,v| @except.include?(k) } unless @except.empty?
32
+ cell = data.only(@only) unless @only.empty?
33
+ cell = data.except(@except) unless @except.empty?
34
34
  csv << (cell || data).values
35
35
  end
36
36
  end
@@ -46,12 +46,12 @@ class ActiveReport::Hash
46
46
  @headers = data
47
47
  else
48
48
  processed_data = {}
49
- @headers.each_with_index do |v,i|
49
+ @headers.each_with_index do |v, i|
50
50
  processed_data.store(v.to_s, data.fetch(i, nil) )
51
51
  end
52
52
 
53
- processed_data.keep_if { |k,v| @only.include?(k) } unless @only.empty?
54
- processed_data.delete_if { |k,v| @except.include?(k) } unless @except.empty?
53
+ processed_data.only!(@only) unless @only.empty?
54
+ processed_data.except!(@except) unless @except.empty?
55
55
 
56
56
  processed_datum.push(processed_data)
57
57
  end
@@ -16,8 +16,8 @@ class ActiveReport::Record
16
16
  new(datum, only: only, except: except, headers: headers, options: options).export
17
17
  end
18
18
 
19
- def self.import(datum, model: nil, only: nil, except: nil, headers: nil, options: {})
20
- new(datum, model: model, only: only, except: except, headers: headers, options: options).import
19
+ def self.import(datum, only: nil, except: nil, headers: nil, options: {}, model: nil)
20
+ new(datum, only: only, except: except, headers: headers, options: options, model: model).import
21
21
  end
22
22
 
23
23
  def export
@@ -26,13 +26,13 @@ class ActiveReport::Record
26
26
  @except = (@except.is_a?(Array) ? @except : [].push(@except).compact).map(&:to_s)
27
27
 
28
28
  CSV.generate(@options) do |csv|
29
- header = @datum.first.dup.keep_if { |k,v| @only.include?(k) } unless @only.empty?
30
- header = @datum.first.dup.delete_if { |k,v| @except.include?(k) } unless @except.empty?
31
- csv << (@headers || (header || @datum.first).keys.map { |k| k.to_s.gsub("_", " ").capitalize})
29
+ header = @datum.first.only(@only) unless @only.empty?
30
+ header = @datum.first.except(@except) unless @except.empty?
31
+ csv << (@headers || (header || @datum.first).keys.map { |k| k.to_s.gsub("_", " ").capitalize })
32
32
 
33
33
  @datum.each do |data|
34
- cell = data.dup.keep_if { |k,v| @only.include?(k) } unless @only.empty?
35
- cell = data.dup.delete_if { |k,v| @except.include?(k) } unless @except.empty?
34
+ cell = data.only(@only) unless @only.empty?
35
+ cell = data.except(@except) unless @except.empty?
36
36
  csv << (cell || data).values
37
37
  end
38
38
  end
@@ -44,8 +44,19 @@ class ActiveReport::Record
44
44
  "Model must be an ActiveRecord::Base object."
45
45
  end
46
46
 
47
- processed_datum = ActiveReport::Hash.import(@datum, headers: @headers, options: @options)
48
- processed_datum.each { |data| @model.create(data) }
47
+ @only = [].push(@only).compact unless @only.is_a?(Array)
48
+ @except = [].push(@except).compact unless @except.is_a?(Array)
49
+
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(" ", "_").to_sym }
53
+ data.except!(:id)
54
+
55
+ data.only!(@only) unless @only.empty?
56
+ data.except!(@except) unless @except.empty?
57
+
58
+ @model.create(data)
59
+ end
49
60
  end
50
61
 
51
62
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveReport
2
- VERSION = "1.2.0"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.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-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: active_object
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: bundler
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +108,34 @@ dependencies:
66
108
  - - ">="
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: database_cleaner
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
69
139
  description: Export or import data from multiple input formats such as arrays, hashes,
70
140
  and active record or vice versa.
71
141
  email: