csv_piper 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2cc21c40bd5c39c089c5044849ff3736dde8f71
4
- data.tar.gz: cd5be979020360ee93d4e647806217258974eaa7
3
+ metadata.gz: 65ef899a794a33e576b88a581d6fda1ed60117a8
4
+ data.tar.gz: 8b8dad00b3d9f1695a18c35797ab16ce94f31021
5
5
  SHA512:
6
- metadata.gz: fa38bd6d4777bcc3486493b92f7faa31c38b1a2db3bac615f12fd15441cb24714b28375e437c223ec23cb842e458a20a5d42ad53ff0216af289d6257352c1d3b
7
- data.tar.gz: 03faf48f923766ff8fccd761b97b965c824cdf485fbbb45eedcc6ddad954a963bbd9f969e1f97bf17fb9ec86bdbcc945619a12a9caaf83abffdffe31b769bd2f
6
+ metadata.gz: cae8257fbb868ecfc14fe1fd924c34fad5e603d2cc166c32da1943c4f19416223601bba7cf19315945d4271220498955f18f2b49f6424a1af0e733155a03dbdd
7
+ data.tar.gz: 61422f90efa60206c57dd4e3d26c072fabf62231059a64d4cd1e130392b3598edee1fc2f2d330f58bb08268cb6507d40e5d318e72bbabc251cbdb957b90b3321
data/README.md CHANGED
@@ -26,6 +26,7 @@ CsvPiper handles CSV reading row by row passing each row through a series of pro
26
26
  * Currently source csv must have headers
27
27
 
28
28
  #### Basic Usage
29
+
29
30
  ```ruby
30
31
  File.open("my/file/path", "r") do |io_stream|
31
32
  CsvPiper::Builder.new.from(io_stream).with_processors([your_processors]).build.process
@@ -37,6 +38,7 @@ end
37
38
 
38
39
  #### Basic Usage with Processors
39
40
  _Extracted from `spec/end_to_end_spec.rb`_
41
+
40
42
  ```ruby
41
43
  # Build some processors beforehand so we can access them later
42
44
  output_collector = CollectProcessedEquations.new
@@ -97,6 +99,7 @@ end
97
99
  Each processor can do whatever it wants, transformation, logging, saving to a database etc.
98
100
 
99
101
  Here is an example of a processor that passes the values from the csv straight along to the transformed output:
102
+
100
103
  ```ruby
101
104
  class PassThrough
102
105
  def process(source, transformed, errors)
@@ -118,6 +121,7 @@ Pre-processors work the same as processors except that their purpose is to modif
118
121
  They are also allowed to add errors against the row.
119
122
 
120
123
  Here is an example of a pre-processor that converts all values to uppercase:
124
+
121
125
  ```ruby
122
126
  class UpCase
123
127
  def process(source, errors)
@@ -152,6 +156,7 @@ Over time we will collect a bunch of general purpose processors that anyone can
152
156
 
153
157
  * `CollectOutput`: Collects the transformed object of every row that is passed through it
154
158
  * `CollectErrors`: Collects the `RowError` object of every row that is passed through it
159
+ * `CreateActiveModel`: Uses the transformed object as attributes and creates using it (Works with ActiveRecord models). Merges errors from model into row errors (Assumes ActiveModel::Errors interface).
155
160
 
156
161
  By using `CollectOutput` and to a lesser extent `CollectErrors` you will start to build up objects in memory. For very large csv files you might not want to use these convenience processors and rather create a new processor that does whatever you need with the row (Ie. log, write to db) which will then be discarded rather than collected.
157
162
 
@@ -159,6 +164,9 @@ Require them explicitly if you want to use them.
159
164
 
160
165
  Eg. `require 'csv_piper/processors/collect_output'`
161
166
 
167
+ ## Inspiration
168
+
169
+ Initial inspiration crystalised upon seeing [Kiba](https://github.com/thbar/kiba). If you need to do extensive ETL (particularly if you don't have csv's) then strongly recommend you check it out.
162
170
 
163
171
  ## Development
164
172
 
data/csv_piper.gemspec CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.10"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3"
26
+ spec.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.10'
27
+ spec.add_development_dependency 'activerecord', '~> 4.2', '>= 4.2.4'
26
28
  end
@@ -0,0 +1,21 @@
1
+ module CsvPiper
2
+ module Processors
3
+ class CreateActiveModel
4
+ def initialize(model_class)
5
+ @model_class = model_class
6
+ end
7
+
8
+ def process(source, transformed, errors)
9
+ model = @model_class.new(transformed)
10
+
11
+ model.save if model.valid? && errors.empty?
12
+
13
+ errors.errors.merge!(model.errors.to_hash) do |key, old_val, new_val|
14
+ old_val + new_val
15
+ end
16
+
17
+ [transformed, errors]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module CsvPiper
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_piper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarrod Sibbison
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-16 00:00:00.000000000 Z
11
+ date: 2015-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,46 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.3.10
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.3'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.3.10
75
+ - !ruby/object:Gem::Dependency
76
+ name: activerecord
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '4.2'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 4.2.4
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '4.2'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 4.2.4
55
95
  description: Simple wrapper to process csv's with a pipeline of testable processors.
56
96
  email:
57
97
  - ''
@@ -75,6 +115,7 @@ files:
75
115
  - lib/csv_piper/pre_processors/remove_extra_columns.rb
76
116
  - lib/csv_piper/processors/collect_errors.rb
77
117
  - lib/csv_piper/processors/collect_output.rb
118
+ - lib/csv_piper/processors/create_active_model.rb
78
119
  - lib/csv_piper/version.rb
79
120
  homepage: https://github.com/jazzarati/csv_piper
80
121
  licenses: