ar_loader 0.0.4 → 0.0.6

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/LICENSE CHANGED
@@ -1,9 +1,9 @@
1
- == ARLoader
2
-
3
- Copyright tom statter @ www.autotelik.co.uk 2011
4
-
5
- Not sure what is appropriate LICENSE
6
-
7
- Free to use in any project, commercial or otherwise as long as copyright not removed ??
8
-
9
- MIT ?
1
+ == ARLoader
2
+
3
+ Copyright tom statter @ www.autotelik.co.uk 2011
4
+
5
+ Not sure what is appropriate LICENSE
6
+
7
+ Free to use in any project, commercial or otherwise as long as copyright not removed ??
8
+
9
+ MIT ?
data/README.markdown CHANGED
@@ -1,211 +1,222 @@
1
- # AR Loader
2
-
3
- General Active Record Loader with current focus on support for Spree.
4
-
5
- Maps column headings to attributes and associations.
6
-
7
- Fully extendable via spreadsheet headings - simply add new column to Excel with
8
- attribute or association name, and loader will attempt to
9
- find correct association and populate AR object with row data.
10
-
11
- Can handle human read-able forms of column names. For example, given an association on AR model called,
12
- product_properties, will map from column headings such as 'product_properties',
13
- 'Product Properties', 'product properties' etc
14
-
15
- ## Installation
16
-
17
- Add gem instruction to your Gemfile. To use the Excel loader, JRuby is required, so to use in a mixed setup
18
- of JRuby and deployed to other Rubies, use the following guard.
19
-
20
- if(RUBY_PLATFORM =~ /java/)
21
- gem 'activerecord-jdbcmysql-adapter'
22
- else
23
- gem 'mysql'
24
- end
25
-
26
- Currently not tested AR usage outside a Rails Project but to install the l;atest gem :
27
-
28
- `gem install ar_loader`
29
-
30
- To pull the tasks in, add call in your Rakefile to :
31
-
32
- ArLoader::require_tasks
33
-
34
- ## Example Spreadsheet
35
-
36
- An example Spreadsheet with headers and comments, suitable for giving to Clients
37
- to populate, can be found in test/examples/DemoSpreadsheet.xls
38
-
39
- ## Features
40
-
41
- - *Direct Excel support*
42
-
43
- Includes a wrapper around MS Excel via Apache POI, which
44
- enables Products to be loaded directly from Excel via JRuby. No need to save to CSV first.
45
-
46
- The java jars e.g - 'poi-3.6.jar' - are included.
47
-
48
- - *Semi-Smart Name Lookup*
49
-
50
- Includes helper classes that find and store details of all possible associations on an AR class.
51
- Given a user supplied name, attempts to find the requested association.
52
-
53
- Example usage, load from a file or spreadsheet where the column names are only
54
- an approximation of the actual associations, so given 'Product Properties' heading,
55
- finds real association 'product_properties' to send or call on the AR object
56
-
57
- - *Associations*
58
-
59
- Can handle 'many' type associations and enables multiple association objects to
60
- be added via single entry (column). See Details section.
61
-
62
- - *Spree Rake Tasks*
63
-
64
- Rake tasks provided for Spree loading - currently supports Product with associations,
65
- and Image loading.
66
-
67
- **Product loading from Excel specifically requires JRuby**.
68
-
69
- Example command lines:
70
-
71
- rake excel_load input=vendor\extensions\autotelik\fixtures\ExampleInfoWeb.xls
72
-
73
- rake excel_load input=C:\MyProducts.xls verbose=true'
74
-
75
- - *Seamless Image loading can be achieved by ensuring SKU or class Name features in Image filename.
76
-
77
- Lookup is performed either via the SKU being prepended to the image name, or by the image name being equal to the **name attribute** of the klass in question.
78
-
79
- Images can be attached to any class defined with a suitable association. The class to use can be configured in rake task via
80
- parameter klass=Xyz.
81
-
82
- In the Spree tasks, this defaults to Product, so attempts to attach Image to a Product via Product SKU or Name.
83
-
84
- Image loading **does not** specifically require JRuby
85
-
86
- A report is generated in the current working directory detailing any Images in the paths that could not be matched with a Product.
87
-
88
- Example cmd lines :
89
-
90
- rake image_load input=vendor\extensions\autotelik\lib\fixtures
91
- rake image_load input="C:\images\Paintings' dummy=true
92
- rake image_load input="C:\images\TaxonIcons" skip_if_no_assoc=true klass=Taxon
93
-
94
- ## Example Wrapper Tasks for Spree Site Extension
95
-
96
- These tasks show how to write your own high level wrapper task, that will seed the database from multiple spreedsheets.
97
-
98
- The images in this example have been named with the SKU present in name (separated by whitespace) e.g "PRINT_001 Stonehenge.jpg"
99
-
100
- A report is generated in the current working directory detailing any Images in the paths that could not be matched with a Product.
101
-
102
- require 'ar_loader'
103
-
104
- namespace :mysite do
105
-
106
- desc "Load Products for site"
107
- task :load, :needs => [:environment] do |t, args|
108
-
109
- [ "vendor/extensions/site/db/seed/Paintings.xls",
110
- "vendor/extensions/site/db/seed/Drawings.xls"
111
- ].each do |x|
112
- Rake::Task['autotelik:excel_load'].execute(
113
- :input => x,
114
- :verbose => true,
115
- :sku_prefix => ""
116
- )
117
- end
118
- end
119
-
120
- desc "Load Images for site based on SKU"
121
- task :load_images, :clean, :dummy, :needs => [:environment] do |t, args|
122
-
123
- if(args[:clean])
124
- Image.delete_all
125
- FileUtils.rm_rf( "public/assests/products" )
126
- end
127
-
128
- ["01_paintings_jpegs", "02_drawings_jpegs"].each do |x|
129
-
130
- # image names start with associated Product SKU,
131
- # skip rather then exit if no matching product found
132
-
133
- Rake::Task['autotelik:image_load'].execute(
134
- :input => "/my_site_load_info//#{x}",
135
- :dummy => args[:dummy],
136
- :verbose => false, :sku => true, :skip_if_no_assoc => true
137
- )
138
- end
139
- end
140
-
141
- ## Details
142
-
143
- ### Associations
144
-
145
- A single association column can contain multiple name/value sets in default form :
146
-
147
- Name1:value1, value2|Name2:value1, value2, value3|Name3:value1, value2 etc
148
-
149
- So for example a Column for an 'Option Types' association on a Product,
150
- could contain 2 options with a number of values each :
151
-
152
- 'Option Types'
153
- size:small,medium,large|colour:red,white
154
- size:small|colour:blue,red,white
155
-
156
- ### Properties
157
-
158
- The properties to associate with this product.
159
- Properties are for small snippets of text, shared across many products,
160
- and are for display purposes only.
161
-
162
- An optional display value can be supplied to supplement the displayed text.
163
-
164
- As for all associations can contain multiple name/value sets in default form :
165
-
166
- Property:display_value|Property:display_value
167
-
168
- Example - No values :
169
- manufacturer|standard
170
-
171
- Example - Display values :
172
- manufacturer:somebody else plc|standard:ISOBlah21
173
-
174
- ## TODO
175
-
176
- - Make more generic, so have smart switching to Ruby and directly support csv,
177
- when JRuby and/or Excel not available.
178
-
179
- - Smart sorting of column processing order ....
180
-
181
- Does not currently ensure mandatory columns (for valid?) processed first.
182
- Since Product needs saving before associations can be processed, user currently
183
- needs to ensure SKU, name, price columns are among first columns
184
-
185
- ## License
186
-
187
- Copyright:: (c) Autotelik Media Ltd 2011
188
-
189
- Author :: Tom Statter
190
-
191
- Date :: Feb 2011
192
-
193
- The MIT License
194
-
195
- Permission is hereby granted, free of charge, to any person obtaining a copy
196
- of this software and associated documentation files (the "Software"), to deal
197
- in the Software without restriction, including without limitation the rights
198
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
199
- copies of the Software, and to permit persons to whom the Software is
200
- furnished to do so, subject to the following conditions:
201
-
202
- The above copyright notice and this permission notice shall be included in
203
- all copies or substantial portions of the Software.
204
-
205
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
206
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
207
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
208
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
209
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
210
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1
+ # AR Loader
2
+
3
+ General Loader for populating database with seed data from various sources.
4
+
5
+ Simplifies the specification and loading of data from files into any active record supported database.
6
+
7
+ Seamlessly handles loading an active record model's attributes and it's associations,
8
+ based on reflection against the supplied model - mapping column headings to attributes and associations.
9
+
10
+ Fully extendable via spreadsheet headings - simply add new column to Excel/Open Office spreadsheets with
11
+ attribute or association name, and loader will attempt to find correct association and populate AR object with row data.
12
+
13
+ Original focus was on support for the Open Source Spree e-commerce project, so includes specific loaders and rake tasks
14
+ for loading Spree Products and associated data such as Product Variants, and images.
15
+
16
+ Loaders attempt to handle various human read-able forms of column names.
17
+
18
+ For example, given an association on the model called, product_properties, will successfully load
19
+ from columns with headings such as 'product_properties', 'Product Properties', 'product Properties' etc
20
+
21
+ ## Installation
22
+
23
+ Add gem instruction to your Gemfile. To use the Excel loader, JRuby is required, so to use in a mixed setup
24
+ of JRuby and deployed to other Rubies, use the following guard.
25
+
26
+ if(RUBY_PLATFORM =~ /java/)
27
+ gem 'activerecord-jdbcmysql-adapter'
28
+ else
29
+ gem 'mysql'
30
+ end
31
+
32
+ Install the latest gem :
33
+
34
+ `gem install ar_loader`
35
+
36
+ To use :
37
+
38
+ require 'ar_loader'
39
+
40
+ To pull the tasks in, add call in your Rakefile :
41
+
42
+ ArLoader::require_tasks
43
+
44
+ ## Example Spreadsheet
45
+
46
+ An example Spreadsheet with headers and comments, suitable for giving to Clients
47
+ to populate, can be found in test/examples/DemoSpreadsheet.xls
48
+
49
+ ## Features
50
+
51
+ - *Direct Excel file support*
52
+
53
+ Includes a wrapper around MS Excel File format, via Apache POI, which
54
+ enables Products to be loaded directly from Excel files (Excel does not need to be installed) via JRuby.
55
+ No need to save to CSV first.
56
+
57
+ The java jars e.g - 'poi-3.6.jar' - are included.
58
+
59
+ - *Semi-Smart Name Lookup*
60
+
61
+ Includes helper classes that find and store details of all possible associations on an AR class.
62
+ Given a user supplied name, attempts to find the requested association.
63
+
64
+ Example usage, load from a file or spreadsheet where the column names are only
65
+ an approximation of the actual associations, so given 'Product Properties' heading,
66
+ finds real association 'product_properties' to send or call on the AR object
67
+
68
+ - *Associations*
69
+
70
+ Can handle 'many' type associations and enables multiple association objects to
71
+ be added via single entry (column). See Details section.
72
+
73
+ - *Spree Rake Tasks*
74
+
75
+ Rake tasks provided for Spree loading - currently supports Product with associations,
76
+ and Image loading.
77
+
78
+ **Product loading from Excel specifically requires JRuby**.
79
+
80
+ Example command lines:
81
+
82
+ rake excel_load input=vendor\extensions\autotelik\fixtures\ExampleInfoWeb.xls
83
+
84
+ rake excel_load input=C:\MyProducts.xls verbose=true'
85
+
86
+ - *Seamless Image loading can be achieved by ensuring SKU or class Name features in Image filename.
87
+
88
+ Lookup is performed either via the SKU being prepended to the image name, or by the image name being equal to the **name attribute** of the klass in question.
89
+
90
+ Images can be attached to any class defined with a suitable association. The class to use can be configured in rake task via
91
+ parameter klass=Xyz.
92
+
93
+ In the Spree tasks, this defaults to Product, so attempts to attach Image to a Product via Product SKU or Name.
94
+
95
+ Image loading **does not** specifically require JRuby
96
+
97
+ A report is generated in the current working directory detailing any Images in the paths that could not be matched with a Product.
98
+
99
+ Example cmd lines :
100
+
101
+ rake image_load input=vendor\extensions\autotelik\lib\fixtures
102
+ rake image_load input="C:\images\Paintings' dummy=true
103
+ rake image_load input="C:\images\TaxonIcons" skip_if_no_assoc=true klass=Taxon
104
+
105
+ ## Example Wrapper Tasks for Spree Site Extension
106
+
107
+ These tasks show how to write your own high level wrapper task, that will seed the database from multiple spreedsheets.
108
+
109
+ The images in this example have been named with the SKU present in name (separated by whitespace) e.g "PRINT_001 Stonehenge.jpg"
110
+
111
+ A report is generated in the current working directory detailing any Images in the paths that could not be matched with a Product.
112
+
113
+ require 'ar_loader'
114
+
115
+ namespace :mysite do
116
+
117
+ desc "Load Products for site"
118
+ task :load, :needs => [:environment] do |t, args|
119
+
120
+ [ "vendor/extensions/site/db/seed/Paintings.xls",
121
+ "vendor/extensions/site/db/seed/Drawings.xls"
122
+ ].each do |x|
123
+ Rake::Task['autotelik:excel_load'].execute(
124
+ :input => x,
125
+ :verbose => true,
126
+ :sku_prefix => ""
127
+ )
128
+ end
129
+ end
130
+
131
+ desc "Load Images for site based on SKU"
132
+ task :load_images, :clean, :dummy, :needs => [:environment] do |t, args|
133
+
134
+ if(args[:clean])
135
+ Image.delete_all
136
+ FileUtils.rm_rf( "public/assests/products" )
137
+ end
138
+
139
+ ["01_paintings_jpegs", "02_drawings_jpegs"].each do |x|
140
+
141
+ # image names start with associated Product SKU,
142
+ # skip rather then exit if no matching product found
143
+
144
+ Rake::Task['autotelik:image_load'].execute(
145
+ :input => "/my_site_load_info//#{x}",
146
+ :dummy => args[:dummy],
147
+ :verbose => false, :sku => true, :skip_if_no_assoc => true
148
+ )
149
+ end
150
+ end
151
+
152
+ ## Details
153
+
154
+ ### Associations
155
+
156
+ A single association column can contain multiple name/value sets in default form :
157
+
158
+ Name1:value1, value2|Name2:value1, value2, value3|Name3:value1, value2 etc
159
+
160
+ So for example a Column for an 'Option Types' association on a Product,
161
+ could contain 2 options with a number of values each :
162
+
163
+ 'Option Types'
164
+ size:small,medium,large|colour:red,white
165
+ size:small|colour:blue,red,white
166
+
167
+ ### Properties
168
+
169
+ The properties to associate with this product.
170
+ Properties are for small snippets of text, shared across many products,
171
+ and are for display purposes only.
172
+
173
+ An optional display value can be supplied to supplement the displayed text.
174
+
175
+ As for all associations can contain multiple name/value sets in default form :
176
+
177
+ Property:display_value|Property:display_value
178
+
179
+ Example - No values :
180
+ manufacturer|standard
181
+
182
+ Example - Display values :
183
+ manufacturer:somebody else plc|standard:ISOBlah21
184
+
185
+ ## TODO
186
+
187
+ - Make more generic, so have smart switching to Ruby and directly support csv,
188
+ when JRuby and/or Excel not available.
189
+
190
+ - Smart sorting of column processing order ....
191
+
192
+ Does not currently ensure mandatory columns (for valid?) processed first.
193
+ Since Product needs saving before associations can be processed, user currently
194
+ needs to ensure SKU, name, price columns are among first columns
195
+
196
+ ## License
197
+
198
+ Copyright:: (c) Autotelik Media Ltd 2011
199
+
200
+ Author :: Tom Statter
201
+
202
+ Date :: Feb 2011
203
+
204
+ The MIT License
205
+
206
+ Permission is hereby granted, free of charge, to any person obtaining a copy
207
+ of this software and associated documentation files (the "Software"), to deal
208
+ in the Software without restriction, including without limitation the rights
209
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
210
+ copies of the Software, and to permit persons to whom the Software is
211
+ furnished to do so, subject to the following conditions:
212
+
213
+ The above copyright notice and this permission notice shall be included in
214
+ all copies or substantial portions of the Software.
215
+
216
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
217
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
218
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
219
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
220
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
221
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
211
222
  THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,76 +1,76 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rake/clean'
4
- require 'rake/gempackagetask'
5
- require 'rake/rdoctask'
6
- require 'rake/testtask'
7
- require "lib/ar_loader"
8
-
9
- # Copyright:: (c) Autotelik Media Ltd 2011
10
- # Author :: Tom Statter
11
- # Date :: Aug 2010
12
- #
13
- # License:: MIT - Free, OpenSource
14
- #
15
- # Details:: Gem::Specification for Active Record Loader gem.
16
- #
17
- # Specifically enabled for uploading Spree products but easily
18
- # extended to any AR model.
19
- #
20
- # Currently support direct access to Excel Spreedsheets via JRuby
21
- #
22
- # TODO - Switch for non JRuby Rubies, enable load via CSV file instead of Excel.
23
- #
24
- ArLoader::require_tasks
25
-
26
- spec = Gem::Specification.new do |s|
27
- s.name = ArLoader.gem_name
28
- s.version = ArLoader.gem_version
29
- s.has_rdoc = true
30
- s.extra_rdoc_files = ['README.markdown', 'LICENSE']
31
- s.summary = 'File based loader for Active Record models'
32
- s.description = 'A file based loader for Active Record models. Seed database directly from Excel/CSV. Includes rake support for Spree'
33
- s.author = 'thomas statter'
34
- s.email = 'rubygems@autotelik.co.uk'
35
- s.date = DateTime.now.strftime("%Y-%m-%d")
36
- s.homepage = %q{http://www.autotelik.co.uk}
37
-
38
- # s.executables = ['your_executable_here']
39
- s.files = %w(LICENSE README.markdown Rakefile) + Dir.glob("{lib,spec,tasks}/**/*")
40
- s.require_path = "lib"
41
- s.bindir = "bin"
42
- end
43
-
44
- Rake::GemPackageTask.new(spec) do |p|
45
- p.gem_spec = spec
46
- p.need_tar = true
47
- p.need_zip = true
48
- end
49
-
50
- Rake::RDocTask.new do |rdoc|
51
- files =['README.markdown', 'LICENSE', 'lib/**/*.rb']
52
- rdoc.rdoc_files.add(files)
53
- rdoc.main = "README.markdown" # page to start on
54
- rdoc.title = "ARLoader Docs"
55
- rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
56
- rdoc.options << '--line-numbers'
57
- end
58
-
59
- Rake::TestTask.new do |t|
60
- t.test_files = FileList['test/**/*.rb']
61
- end
62
-
63
- # Add in our own Tasks
64
-
65
- # Long parameter lists so ensure rake -T produces nice wide output
66
- ENV['RAKE_COLUMNS'] = '180'
67
-
68
- desc 'Build gem and install in one step'
69
- task :pik_install, :needs => [:gem] do |t, args|
70
-
71
- puts "Installing version #{ArLoader.gem_version}"
72
-
73
- gem = "#{ArLoader.gem_name}-#{ArLoader.gem_version}.gem"
74
- cmd = "pik gem install --no-ri --no-rdoc pkg\\#{gem}"
75
- system(cmd)
76
- end
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'rake/testtask'
7
+ require "lib/ar_loader"
8
+
9
+ # Copyright:: (c) Autotelik Media Ltd 2011
10
+ # Author :: Tom Statter
11
+ # Date :: Aug 2010
12
+ #
13
+ # License:: MIT - Free, OpenSource
14
+ #
15
+ # Details:: Gem::Specification for Active Record Loader gem.
16
+ #
17
+ # Specifically enabled for uploading Spree products but easily
18
+ # extended to any AR model.
19
+ #
20
+ # Currently support direct access to Excel Spreedsheets via JRuby
21
+ #
22
+ # TODO - Switch for non JRuby Rubies, enable load via CSV file instead of Excel.
23
+ #
24
+ ArLoader::require_tasks
25
+
26
+ spec = Gem::Specification.new do |s|
27
+ s.name = ArLoader.gem_name
28
+ s.version = ArLoader.gem_version
29
+ s.has_rdoc = true
30
+ s.extra_rdoc_files = ['README.markdown', 'LICENSE']
31
+ s.summary = 'File based loader for Active Record models'
32
+ s.description = 'A file based loader for Active Record models. Seed database directly from Excel/CSV. Includes rake support for Spree'
33
+ s.author = 'thomas statter'
34
+ s.email = 'rubygems@autotelik.co.uk'
35
+ s.date = DateTime.now.strftime("%Y-%m-%d")
36
+ s.homepage = %q{http://www.autotelik.co.uk}
37
+
38
+ # s.executables = ['your_executable_here']
39
+ s.files = %w(LICENSE README.markdown Rakefile) + Dir.glob("{lib,spec,tasks}/**/*")
40
+ s.require_path = "lib"
41
+ s.bindir = "bin"
42
+ end
43
+
44
+ Rake::GemPackageTask.new(spec) do |p|
45
+ p.gem_spec = spec
46
+ p.need_tar = true
47
+ p.need_zip = true
48
+ end
49
+
50
+ Rake::RDocTask.new do |rdoc|
51
+ files =['README.markdown', 'LICENSE', 'lib/**/*.rb']
52
+ rdoc.rdoc_files.add(files)
53
+ rdoc.main = "README.markdown" # page to start on
54
+ rdoc.title = "ARLoader Docs"
55
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
56
+ rdoc.options << '--line-numbers'
57
+ end
58
+
59
+ Rake::TestTask.new do |t|
60
+ t.test_files = FileList['test/**/*.rb']
61
+ end
62
+
63
+ # Add in our own Tasks
64
+
65
+ # Long parameter lists so ensure rake -T produces nice wide output
66
+ ENV['RAKE_COLUMNS'] = '180'
67
+
68
+ desc 'Build gem and install in one step'
69
+ task :pik_install, :needs => [:gem] do |t, args|
70
+
71
+ puts "Installing version #{ArLoader.gem_version}"
72
+
73
+ gem = "#{ArLoader.gem_name}-#{ArLoader.gem_version}.gem"
74
+ cmd = "pik gem install --no-ri --no-rdoc pkg\\#{gem}"
75
+ system(cmd)
76
+ end
data/lib/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.6