davidrichards-etl 0.0.6 → 0.0.7

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.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 6
4
+ :patch: 7
@@ -1,50 +1,50 @@
1
- # # This is a base class that uses ETL and Zach Dennis' excellent ar-
2
- # # extensions gem. To get the gem, just:
3
- # #
4
- # # sudo gem install ar-extensions
5
- # #
6
- # # See:
7
- # # http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/
8
- # # http://agilewebdevelopment.com/plugins/ar_extensions
9
- # # http://www.continuousthinking.com/
1
+ # This is a base class that uses ETL and Zach Dennis' excellent ar-
2
+ # extensions gem. To get the gem, just:
10
3
  #
11
- # # To use this, 1) setup an extract to find the data, and 2) a transform to
12
- # # create an array of arrays, with the first array as the header. The
13
- # # header and data should only contain values in the table to be imported.
14
- # # The data_frame gem (sudo gem install davidrichards-data_frame)
15
- # # may make the transform a LOT easier to do if there is a lot of column
16
- # # munging to do. Chris Wycoff's babel_icious gem will go a long way in
17
- # # the transform if you have XML data you are working with
18
- # # (sudo gem install cwycoff-babel_icious).
4
+ # sudo gem install ar-extensions
19
5
  #
20
- # class ActiveRecordLoader < ETL
21
- #
22
- # after_transform :ensure_array_of_arrays
23
- # before_load :ensure_class_defined
24
- # before_load :assert_header
25
- #
26
- # protected
27
- #
28
- # def ensure_array_of_arrays
29
- # # Not 100% whether I process raw_data before or after this method. I think before.
30
- # data = @raw || @data
31
- # raise ArgumentError,
32
- # "Expecting transformed data to be an array of arays" unless
33
- # data.is_a?(Array) and data.first.is_a?(Array) and data.last.is_a?(Array)
34
- # end
35
- #
36
- # def assert_header
37
- # @header ||= @data.shift
38
- # @header.symbolize_values!
39
- # end
40
- #
41
- # def ensure_class_defined
42
- # raise ArgumentError,
43
- # "Must provide a class to import to. Try #{self.to_a}.instance.options[:class] = ModelClassName" unless
44
- # self.options[:class]
45
- # end
46
- #
47
- # def load
48
- # options[:class].import(@header, @data)
49
- # end
50
- # end
6
+ # See:
7
+ # http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/
8
+ # http://agilewebdevelopment.com/plugins/ar_extensions
9
+ # http://www.continuousthinking.com/
10
+
11
+ # To use this, 1) setup an extract to find the data, and 2) a transform to
12
+ # create an array of arrays, with the first array as the header. The
13
+ # header and data should only contain values in the table to be imported.
14
+ # The data_frame gem (sudo gem install davidrichards-data_frame)
15
+ # may make the transform a LOT easier to do if there is a lot of column
16
+ # munging to do. Chris Wycoff's babel_icious gem will go a long way in
17
+ # the transform if you have XML data you are working with
18
+ # (sudo gem install cwycoff-babel_icious).
19
+
20
+ class ActiveRecordLoader < ETL
21
+
22
+ after_transform :ensure_array_of_arrays
23
+ before_load :ensure_class_defined
24
+ before_load :assert_header
25
+
26
+ protected
27
+
28
+ def ensure_array_of_arrays
29
+ # Not 100% whether I process raw_data before or after this method. I think before.
30
+ data = @raw || @data
31
+ raise ArgumentError,
32
+ "Expecting transformed data to be an array of arays" unless
33
+ data.is_a?(Array) and data.first.is_a?(Array) and data.last.is_a?(Array)
34
+ end
35
+
36
+ def assert_header
37
+ @header ||= @data.shift
38
+ @header.symbolize_values!
39
+ end
40
+
41
+ def ensure_class_defined
42
+ raise ArgumentError,
43
+ "Must provide a class to import to. Try #{self.to_a}.instance.options[:class] = ModelClassName" unless
44
+ self.options[:class]
45
+ end
46
+
47
+ def load
48
+ options[:class].import(@header, @data)
49
+ end
50
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: davidrichards-etl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Richards
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-09 00:00:00 -07:00
12
+ date: 2009-08-15 00:00:00 -07:00
13
13
  default_executable: etl
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency