datashift 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +211 -0
- data/LICENSE.txt +27 -0
- data/README.markdown +286 -0
- data/README.rdoc +19 -0
- data/Rakefile +96 -0
- data/VERSION +5 -0
- data/bin/autospec +16 -0
- data/bin/convert_to_should_syntax +16 -0
- data/bin/erubis +16 -0
- data/bin/htmldiff +16 -0
- data/bin/jeweler +16 -0
- data/bin/ldiff +16 -0
- data/bin/nokogiri +16 -0
- data/bin/rackup +16 -0
- data/bin/rails +16 -0
- data/bin/rake +16 -0
- data/bin/rake2thor +16 -0
- data/bin/ri +16 -0
- data/bin/rspec +16 -0
- data/bin/spree +16 -0
- data/bin/thor +16 -0
- data/bin/tilt +16 -0
- data/bin/tt +16 -0
- data/datashift.gemspec +178 -0
- data/lib/applications/jruby/jexcel_file.rb +397 -0
- data/lib/applications/jruby/word.rb +79 -0
- data/lib/datashift.rb +114 -0
- data/lib/datashift/exceptions.rb +12 -0
- data/lib/datashift/file_definitions.rb +353 -0
- data/lib/datashift/mapping_file_definitions.rb +88 -0
- data/lib/datashift/method_detail.rb +237 -0
- data/lib/datashift/method_mapper.rb +257 -0
- data/lib/generators/csv_generator.rb +36 -0
- data/lib/generators/excel_generator.rb +122 -0
- data/lib/generators/generator_base.rb +14 -0
- data/lib/helpers/core_ext/to_b.rb +24 -0
- data/lib/helpers/spree_helper.rb +131 -0
- data/lib/java/poi-3.7/._poi-3.7-20101029.jar5645100390082102460.tmp +0 -0
- data/lib/java/poi-3.7/LICENSE +507 -0
- data/lib/java/poi-3.7/NOTICE +21 -0
- data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -0
- data/lib/java/poi-3.7/lib/commons-logging-1.1.jar +0 -0
- data/lib/java/poi-3.7/lib/junit-3.8.1.jar +0 -0
- data/lib/java/poi-3.7/lib/log4j-1.2.13.jar +0 -0
- data/lib/java/poi-3.7/ooxml-lib/dom4j-1.6.1.jar +0 -0
- data/lib/java/poi-3.7/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar +0 -0
- data/lib/java/poi-3.7/ooxml-lib/xmlbeans-2.3.0.jar +0 -0
- data/lib/java/poi-3.7/poi-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-examples-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-ooxml-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-ooxml-schemas-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-scratchpad-3.7-20101029.jar +0 -0
- data/lib/loaders/csv_loader.rb +99 -0
- data/lib/loaders/excel_loader.rb +150 -0
- data/lib/loaders/loader_base.rb +332 -0
- data/lib/loaders/spreadsheet_loader.rb +137 -0
- data/lib/loaders/spree/image_loader.rb +46 -0
- data/lib/loaders/spree/product_loader.rb +225 -0
- data/spec/csv_loader_spec.rb +31 -0
- data/spec/datashift_spec.rb +27 -0
- data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -0
- data/spec/excel_generator_spec.rb +79 -0
- data/spec/excel_loader_spec.rb +177 -0
- data/spec/file_definitions.rb +141 -0
- data/spec/fixtures/BadAssociationName.xls +0 -0
- data/spec/fixtures/DemoNegativeTesting.xls +0 -0
- data/spec/fixtures/ProjectsMultiCategories.xls +0 -0
- data/spec/fixtures/ProjectsSingleCategories.xls +0 -0
- data/spec/fixtures/SimpleProjects.xls +0 -0
- data/spec/fixtures/config/database.yml +25 -0
- data/spec/fixtures/interact_models_db.sqlite +0 -0
- data/spec/fixtures/interact_spree_db.sqlite +0 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.xls +0 -0
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -0
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.xls +0 -0
- data/spec/fixtures/simple_export_spec.xls +0 -0
- data/spec/fixtures/simple_template_spec.xls +0 -0
- data/spec/fixtures/spree/SpreeProducts.csv +4 -0
- data/spec/fixtures/spree/SpreeProducts.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -0
- data/spec/fixtures/spree/SpreeProductsSimple.xls +0 -0
- data/spec/fixtures/spree/SpreeZoneExample.csv +5 -0
- data/spec/fixtures/spree/SpreeZoneExample.xls +0 -0
- data/spec/fixtures/test_model_defs.rb +57 -0
- data/spec/loader_spec.rb +121 -0
- data/spec/method_mapper_spec.rb +238 -0
- data/spec/spec_helper.rb +116 -0
- data/spec/spree_generator_spec.rb +65 -0
- data/spec/spree_loader_spec.rb +311 -0
- data/spec/spree_method_mapping_spec.rb +215 -0
- data/tasks/config/seed_fu_product_template.erb +15 -0
- data/tasks/config/tidy_config.txt +13 -0
- data/tasks/db_tasks.rake +65 -0
- data/tasks/excel_generator.rake +79 -0
- data/tasks/file_tasks.rake +37 -0
- data/tasks/import/csv.rake +50 -0
- data/tasks/import/excel.rake +67 -0
- data/tasks/spree/image_load.rake +109 -0
- data/tasks/spree/product_loader.rake +44 -0
- data/tasks/word_to_seedfu.rake +167 -0
- data/test/helper.rb +18 -0
- data/test/test_interact.rb +7 -0
- metadata +301 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rails", '3.1.3'
|
10
|
+
gem "activerecord", '3.1.3'
|
11
|
+
gem "activesupport", '3.1.3'
|
12
|
+
|
13
|
+
platform :jruby do
|
14
|
+
gem 'jruby-openssl'
|
15
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
16
|
+
end
|
17
|
+
|
18
|
+
gem 'spree', '0.70.3'
|
19
|
+
gem "rspec", ">= 0"
|
20
|
+
gem "shoulda", ">= 0"
|
21
|
+
gem "rdoc", "~> 3.12"
|
22
|
+
gem "bundler", "~> 1.0.0"
|
23
|
+
gem "jeweler", "~> 1.8.3"
|
24
|
+
end
|
25
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.1.3)
|
5
|
+
actionpack (= 3.1.3)
|
6
|
+
mail (~> 2.3.0)
|
7
|
+
actionpack (3.1.3)
|
8
|
+
activemodel (= 3.1.3)
|
9
|
+
activesupport (= 3.1.3)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
i18n (~> 0.6)
|
13
|
+
rack (~> 1.3.5)
|
14
|
+
rack-cache (~> 1.1)
|
15
|
+
rack-mount (~> 0.8.2)
|
16
|
+
rack-test (~> 0.6.1)
|
17
|
+
sprockets (~> 2.0.3)
|
18
|
+
activemerchant (1.17.0)
|
19
|
+
activesupport (>= 2.3.11)
|
20
|
+
braintree (>= 2.0.0)
|
21
|
+
builder (>= 2.0.0)
|
22
|
+
json (>= 1.5.1)
|
23
|
+
activemodel (3.1.3)
|
24
|
+
activesupport (= 3.1.3)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
i18n (~> 0.6)
|
27
|
+
activerecord (3.1.3)
|
28
|
+
activemodel (= 3.1.3)
|
29
|
+
activesupport (= 3.1.3)
|
30
|
+
arel (~> 2.2.1)
|
31
|
+
tzinfo (~> 0.3.29)
|
32
|
+
activerecord-jdbc-adapter (1.2.2)
|
33
|
+
activerecord-jdbcsqlite3-adapter (1.2.2)
|
34
|
+
activerecord-jdbc-adapter (~> 1.2.2)
|
35
|
+
jdbc-sqlite3 (~> 3.7.2)
|
36
|
+
activeresource (3.1.3)
|
37
|
+
activemodel (= 3.1.3)
|
38
|
+
activesupport (= 3.1.3)
|
39
|
+
activesupport (3.1.3)
|
40
|
+
multi_json (~> 1.0)
|
41
|
+
acts_as_list (0.1.4)
|
42
|
+
arel (2.2.1)
|
43
|
+
bcrypt-ruby (3.0.1-java)
|
44
|
+
bouncy-castle-java (1.5.0146.1)
|
45
|
+
braintree (2.13.3)
|
46
|
+
builder (>= 2.0.0)
|
47
|
+
builder (3.0.0)
|
48
|
+
cancan (1.6.5)
|
49
|
+
cocaine (0.2.1)
|
50
|
+
deface (0.7.2)
|
51
|
+
nokogiri (~> 1.5.0)
|
52
|
+
rails (>= 3.0.9)
|
53
|
+
devise (1.4.7)
|
54
|
+
bcrypt-ruby (~> 3.0)
|
55
|
+
orm_adapter (~> 0.0.3)
|
56
|
+
warden (~> 1.0.3)
|
57
|
+
diff-lcs (1.1.3)
|
58
|
+
erubis (2.7.0)
|
59
|
+
faker (1.0.0)
|
60
|
+
i18n (~> 0.4)
|
61
|
+
git (1.2.5)
|
62
|
+
highline (1.6.2)
|
63
|
+
hike (1.2.1)
|
64
|
+
i18n (0.6.0)
|
65
|
+
jdbc-sqlite3 (3.7.2)
|
66
|
+
jeweler (1.8.3)
|
67
|
+
bundler (~> 1.0)
|
68
|
+
git (>= 1.2.5)
|
69
|
+
rake
|
70
|
+
rdoc
|
71
|
+
jquery-rails (1.0.19)
|
72
|
+
railties (~> 3.0)
|
73
|
+
thor (~> 0.14)
|
74
|
+
jruby-openssl (0.7.5)
|
75
|
+
bouncy-castle-java (>= 1.5.0146.1)
|
76
|
+
json (1.6.5-java)
|
77
|
+
kaminari (0.13.0)
|
78
|
+
actionpack (>= 3.0.0)
|
79
|
+
activesupport (>= 3.0.0)
|
80
|
+
railties (>= 3.0.0)
|
81
|
+
mail (2.3.0)
|
82
|
+
i18n (>= 0.4.0)
|
83
|
+
mime-types (~> 1.16)
|
84
|
+
treetop (~> 1.4.8)
|
85
|
+
meta_search (1.1.1)
|
86
|
+
actionpack (~> 3.1.0)
|
87
|
+
activerecord (~> 3.1.0)
|
88
|
+
activesupport (~> 3.1.0)
|
89
|
+
polyamorous (~> 0.5.0)
|
90
|
+
mime-types (1.17.2)
|
91
|
+
multi_json (1.0.4)
|
92
|
+
nested_set (1.6.8)
|
93
|
+
activerecord (>= 3.0.0)
|
94
|
+
railties (>= 3.0.0)
|
95
|
+
nokogiri (1.5.0-java)
|
96
|
+
orm_adapter (0.0.6)
|
97
|
+
paperclip (2.4.1)
|
98
|
+
activerecord (>= 2.3.0)
|
99
|
+
activesupport (>= 2.3.2)
|
100
|
+
cocaine (>= 0.0.2)
|
101
|
+
mime-types
|
102
|
+
polyamorous (0.5.0)
|
103
|
+
activerecord (~> 3.0)
|
104
|
+
polyglot (0.3.3)
|
105
|
+
rack (1.3.6)
|
106
|
+
rack-cache (1.1)
|
107
|
+
rack (>= 0.4)
|
108
|
+
rack-mount (0.8.3)
|
109
|
+
rack (>= 1.0.0)
|
110
|
+
rack-ssl (1.3.2)
|
111
|
+
rack
|
112
|
+
rack-test (0.6.1)
|
113
|
+
rack (>= 1.0)
|
114
|
+
rails (3.1.3)
|
115
|
+
actionmailer (= 3.1.3)
|
116
|
+
actionpack (= 3.1.3)
|
117
|
+
activerecord (= 3.1.3)
|
118
|
+
activeresource (= 3.1.3)
|
119
|
+
activesupport (= 3.1.3)
|
120
|
+
bundler (~> 1.0)
|
121
|
+
railties (= 3.1.3)
|
122
|
+
railties (3.1.3)
|
123
|
+
actionpack (= 3.1.3)
|
124
|
+
activesupport (= 3.1.3)
|
125
|
+
rack-ssl (~> 1.3.2)
|
126
|
+
rake (>= 0.8.7)
|
127
|
+
rdoc (~> 3.4)
|
128
|
+
thor (~> 0.14.6)
|
129
|
+
rake (0.9.2.2)
|
130
|
+
rd_find_by_param (0.1.1)
|
131
|
+
activerecord (~> 3.0)
|
132
|
+
activesupport (~> 3.0)
|
133
|
+
rd_resource_controller (1.0.1)
|
134
|
+
rdoc (3.12)
|
135
|
+
json (~> 1.4)
|
136
|
+
rspec (2.8.0)
|
137
|
+
rspec-core (~> 2.8.0)
|
138
|
+
rspec-expectations (~> 2.8.0)
|
139
|
+
rspec-mocks (~> 2.8.0)
|
140
|
+
rspec-core (2.8.0)
|
141
|
+
rspec-expectations (2.8.0)
|
142
|
+
diff-lcs (~> 1.1.2)
|
143
|
+
rspec-mocks (2.8.0)
|
144
|
+
shoulda (2.11.3)
|
145
|
+
spree (0.70.3)
|
146
|
+
spree_api (= 0.70.3)
|
147
|
+
spree_auth (= 0.70.3)
|
148
|
+
spree_core (= 0.70.3)
|
149
|
+
spree_dash (= 0.70.3)
|
150
|
+
spree_promo (= 0.70.3)
|
151
|
+
spree_sample (= 0.70.3)
|
152
|
+
spree_api (0.70.3)
|
153
|
+
spree_auth (= 0.70.3)
|
154
|
+
spree_core (= 0.70.3)
|
155
|
+
spree_auth (0.70.3)
|
156
|
+
cancan (= 1.6.5)
|
157
|
+
devise (= 1.4.7)
|
158
|
+
spree_core (= 0.70.3)
|
159
|
+
spree_core (0.70.3)
|
160
|
+
activemerchant (= 1.17.0)
|
161
|
+
acts_as_list (= 0.1.4)
|
162
|
+
deface (>= 0.7.0)
|
163
|
+
faker (= 1.0.0)
|
164
|
+
highline (= 1.6.2)
|
165
|
+
jquery-rails (>= 1.0.14)
|
166
|
+
kaminari (>= 0.12.4)
|
167
|
+
meta_search (= 1.1.1)
|
168
|
+
nested_set (= 1.6.8)
|
169
|
+
paperclip (= 2.4.1)
|
170
|
+
rails (>= 3.1.1, <= 3.1.3)
|
171
|
+
rd_find_by_param (= 0.1.1)
|
172
|
+
rd_resource_controller
|
173
|
+
state_machine (= 1.0.1)
|
174
|
+
stringex (= 1.0.3)
|
175
|
+
spree_dash (0.70.3)
|
176
|
+
spree_core (= 0.70.3)
|
177
|
+
spree_promo (0.70.3)
|
178
|
+
spree_auth (= 0.70.3)
|
179
|
+
spree_core (= 0.70.3)
|
180
|
+
spree_sample (0.70.3)
|
181
|
+
spree_core (= 0.70.3)
|
182
|
+
sprockets (2.0.3)
|
183
|
+
hike (~> 1.2)
|
184
|
+
rack (~> 1.0)
|
185
|
+
tilt (~> 1.1, != 1.3.0)
|
186
|
+
state_machine (1.0.1)
|
187
|
+
stringex (1.0.3)
|
188
|
+
thor (0.14.6)
|
189
|
+
tilt (1.3.3)
|
190
|
+
treetop (1.4.10)
|
191
|
+
polyglot
|
192
|
+
polyglot (>= 0.3.1)
|
193
|
+
tzinfo (0.3.31)
|
194
|
+
warden (1.0.6)
|
195
|
+
rack (>= 1.0)
|
196
|
+
|
197
|
+
PLATFORMS
|
198
|
+
java
|
199
|
+
|
200
|
+
DEPENDENCIES
|
201
|
+
activerecord (= 3.1.3)
|
202
|
+
activerecord-jdbcsqlite3-adapter
|
203
|
+
activesupport (= 3.1.3)
|
204
|
+
bundler (~> 1.0.0)
|
205
|
+
jeweler (~> 1.8.3)
|
206
|
+
jruby-openssl
|
207
|
+
rails (= 3.1.3)
|
208
|
+
rdoc (~> 3.12)
|
209
|
+
rspec
|
210
|
+
shoulda
|
211
|
+
spree (= 0.70.3)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
== DataShift
|
2
|
+
|
3
|
+
## License
|
4
|
+
|
5
|
+
Copyright:: (c) Autotelik Media Ltd 2011
|
6
|
+
Author :: Tom Statter
|
7
|
+
Date :: Sept 2011
|
8
|
+
|
9
|
+
The MIT License
|
10
|
+
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
13
|
+
in the Software without restriction, including without limitation the rights
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
16
|
+
furnished to do so, subject to the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be included in
|
19
|
+
all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
27
|
+
THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,286 @@
|
|
1
|
+
## DataShift
|
2
|
+
|
3
|
+
Provides tools to shift data between Ruby, external applications, files and ActiveRecord.
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
Map Active Record models and associations to files.
|
8
|
+
|
9
|
+
Import and Export ActiveRecord based data through .xls or CSV files.
|
10
|
+
|
11
|
+
Create, parse and use Excel/OpenOffice (.xls) documents dynamically from Ruby.
|
12
|
+
|
13
|
+
High level rake tasks provided.
|
14
|
+
|
15
|
+
Spree E-Commerce specific loaders and rake tasks provided enabling import/export of all data including Products with
|
16
|
+
complex associations such as Options/Variants and Images.
|
17
|
+
|
18
|
+
Example spreadsheets, fully documented with comments for each column.
|
19
|
+
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add gem 'datashift' to your Gemfile/bundle, or install the latest gem as usual :
|
24
|
+
|
25
|
+
`gem install datashift`
|
26
|
+
|
27
|
+
To use :
|
28
|
+
|
29
|
+
gem 'datashift'
|
30
|
+
require 'datashift'
|
31
|
+
|
32
|
+
To pull the tasks in, add this call to your Rakefile :
|
33
|
+
|
34
|
+
DataShift ::load_tasks
|
35
|
+
|
36
|
+
N.B - To use the Excel loader, OLE and Excel are NOT required, however
|
37
|
+
JRuby is required, since it uses Java's Apache POI under the hood to process .xls files.
|
38
|
+
|
39
|
+
Guards are provided, and used internally, for mixed Ruby setups. Can be used like :
|
40
|
+
|
41
|
+
if(DataShift::Guards::jruby? )
|
42
|
+
..do something with Excel
|
43
|
+
else
|
44
|
+
..do something with CSV
|
45
|
+
end
|
46
|
+
|
47
|
+
## Active Record - Import/Export
|
48
|
+
|
49
|
+
Provides wrappers and rake tasks for importing/exporting data to DBs, from various sources,
|
50
|
+
including csv and .xls files (Excel/Open Office)
|
51
|
+
|
52
|
+
Simplifies the exchange of data, between such files and any active record supported database.
|
53
|
+
|
54
|
+
A core feature of DataShift is the MethodMapper, which provides features for collecting
|
55
|
+
reflection information from ActiveRecord models (all different associations, including join tables with many-to-many relationships).
|
56
|
+
|
57
|
+
A full picture of all possible operations on a class can be created very easily, for example ona Blog model :
|
58
|
+
|
59
|
+
MethodMapper.find_operators( Blog )
|
60
|
+
|
61
|
+
This then allows Import/Export to be achieved, by mapping the file's header and column data to MethodMapper's operators
|
62
|
+
(i.e. the model's attributes and associations).
|
63
|
+
|
64
|
+
Here we retrieve the method details for a column name from a file, "Blog Date"
|
65
|
+
|
66
|
+
MethodMapper.find_method_detail( Blog, "Blog Date" )
|
67
|
+
|
68
|
+
Loaders can use this method lookup functionality, to find the correct association for a column heading,
|
69
|
+
and populate AR object with row data.
|
70
|
+
|
71
|
+
This means data can be mapped to any model without any further coding. Generators are also supplied to export
|
72
|
+
a models attributes and associations to files, thus providing template spreadsheets that any user can fill out.
|
73
|
+
|
74
|
+
MethodMapper also stores column type information so the raw file data can be provided as is,
|
75
|
+
and whenever possible, under the bonnet the data will be cast to correct DB type.
|
76
|
+
|
77
|
+
Here we show how a column name from a file, "Blog Date", can be mapped to Assign a stringified date, to the blog_date column, on a new Blog object :
|
78
|
+
|
79
|
+
MethodMapper.find_method_detail( Blog, "Blog Date" ).assign( Blog.new, "Sat Jul 23 2011" )
|
80
|
+
|
81
|
+
Because it's based on reflection against the model, can build complex relationships between tables during import/export,
|
82
|
+
and extending data files with new columns need not require any additional Ruby coding.
|
83
|
+
|
84
|
+
New columns can simply be added to the Excel/Open Office spreadsheet, or CSV file, setting the new
|
85
|
+
attribute or association name in the header row.
|
86
|
+
|
87
|
+
|
88
|
+
The Loader attempts to handle various human read-able forms of column names.
|
89
|
+
|
90
|
+
For example, given an association on the model called, product_properties, will successfully load
|
91
|
+
from columns with headings such as 'product_properties', 'Product Properties', 'ProductProperties' 'product properties' etc
|
92
|
+
|
93
|
+
For has_many associations, either multiple columns can be used,
|
94
|
+
or multiple values can be specified in a single column using suitable delimiters.
|
95
|
+
|
96
|
+
Modular - so complex associations/mappings that require non generic lookups, can be handled by extending the loader engine.
|
97
|
+
|
98
|
+
Original focus was on support for the Open Source Spree e-commerce project, so includes specific loaders and rake tasks
|
99
|
+
for loading Spree Products, and associated data such as Product Variants, and Images.
|
100
|
+
|
101
|
+
## Template Generation and Export
|
102
|
+
|
103
|
+
Template generation tasks can be used to export a model's definition as column headings to CSV or .xls.
|
104
|
+
These can be provided to developers or business users, as a template for data collection and then loading.
|
105
|
+
|
106
|
+
Export tasks can be used to export of a model's definition and any existing data stored in the database.
|
107
|
+
|
108
|
+
This data can be exported directly to CSV or Excel/OpenOffice spreadsheets.
|
109
|
+
|
110
|
+
|
111
|
+
## Example Spreadsheets
|
112
|
+
|
113
|
+
A number of example Spreadsheets with headers and comments, can be found in the spec/fixtures directory.
|
114
|
+
|
115
|
+
Extensive Spree samples - including .xls and csv versions for simple Products or complex Products with multiple
|
116
|
+
taxons, variants properties etc - can be found in the spec/fixtures/spree subdirectory.
|
117
|
+
|
118
|
+
Column headings contain comments with full descriptions and instructions on syntax.
|
119
|
+
|
120
|
+
|
121
|
+
## Features
|
122
|
+
|
123
|
+
- *High level wrappers around applications including Excel and Word
|
124
|
+
|
125
|
+
Quickly and easily access common enterprise applications through Ruby
|
126
|
+
|
127
|
+
Wrapper around MS Excel File format, acheived via Apache POI under JRuby, so not restricted to Windows
|
128
|
+
and Excel does not need to be installed.
|
129
|
+
|
130
|
+
The required POI jars are already included.
|
131
|
+
|
132
|
+
- *Direct Excel export*
|
133
|
+
|
134
|
+
Excel/OpenOffice spreadsheets are heavily used in many sectors, so direct support makes it
|
135
|
+
easier and quicker to migrate your client's data into a Rails/ActiveRecord project.
|
136
|
+
|
137
|
+
No need to save to CSV or map to YAML.
|
138
|
+
|
139
|
+
- *Semi-Smart Name Lookup*
|
140
|
+
|
141
|
+
Includes helper classes that find and store details of all possible associations on an AR class.
|
142
|
+
Given a user supplied name, attempts to find the requested association.
|
143
|
+
|
144
|
+
Example usage, load from a file or spreadsheet where the column names are only
|
145
|
+
an approximation of the actual associations, so given 'Product Properties' heading,
|
146
|
+
finds real association 'product_properties' to send or call on the AR object
|
147
|
+
|
148
|
+
- *Associations*
|
149
|
+
|
150
|
+
Can handle 'belongs_to, 'has_many' and 'has_one' associations, including assignment of multiple objects
|
151
|
+
via either multiple columns, or via specially delimited entry in a single (column). See Details section.
|
152
|
+
|
153
|
+
Supports delegated attributes.
|
154
|
+
|
155
|
+
- *Rake Tasks*
|
156
|
+
|
157
|
+
High level Rake tasks are provided, only required to supply model class, and file location :
|
158
|
+
|
159
|
+
jruby -S rake datashift:import:excel model=MusicTrack input=MyTrackListing.xls
|
160
|
+
|
161
|
+
|
162
|
+
- *Spree Rake Tasks*
|
163
|
+
|
164
|
+
Specific Rake tasks are also provided for Spree loading - currently supports Product with associations,
|
165
|
+
and Image loading.
|
166
|
+
|
167
|
+
jruby -S rake datashift:spree:products input=C:\MyProducts.xls
|
168
|
+
|
169
|
+
|
170
|
+
**Product loading from Excel files specifically requires JRuby (But not Excel or OLE)**.
|
171
|
+
|
172
|
+
|
173
|
+
- *Seamless Spree Image loading can be achieved by ensuring SKU or class Name features in Image filename.
|
174
|
+
|
175
|
+
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.
|
176
|
+
|
177
|
+
Images can be attached to any class defined with a suitable association. The class to use can be configured in rake task via
|
178
|
+
parameter klass=Xyz.
|
179
|
+
|
180
|
+
In the Spree tasks, this defaults to Product, so attempts to attach Image to a Product via Product SKU or Name.
|
181
|
+
|
182
|
+
Image loading **does not** specifically require JRuby
|
183
|
+
|
184
|
+
A report is generated in the current working directory detailing any Images in the paths that could not be matched with a Product.
|
185
|
+
|
186
|
+
rake datashift:spree:images input=C:\images\product_images skip_if_no_assoc=true
|
187
|
+
|
188
|
+
rake datashift:spree:images input=C:\images\taxon_icons skip_if_no_assoc=true klass=Taxon
|
189
|
+
|
190
|
+
## Import to Active Record
|
191
|
+
|
192
|
+
### Associations
|
193
|
+
|
194
|
+
To perform a lookup for an associated model, the primary column(s) must be supplied, along with required select values for those columns.
|
195
|
+
|
196
|
+
A single association column can contain multiple name/value sets, in string form :
|
197
|
+
|
198
|
+
column:lookup_key_1, lookup_key_2,...
|
199
|
+
|
200
|
+
So if our Project model has many Categories, we can supply a Category list, which is keyed on the column Category.reference with :
|
201
|
+
|
202
|
+
|Categories|
|
203
|
+
|
204
|
+
reference:category_001,category_002
|
205
|
+
|
206
|
+
During loading, a call to find_all_by_reference will be made, picking up the 2 categories with matching references,
|
207
|
+
and our Project model will contain those two i.e project.categories = [category_002,category_003]
|
208
|
+
|
209
|
+
## Spree Suppprt
|
210
|
+
|
211
|
+
### OptionTypes & Variants
|
212
|
+
|
213
|
+
When loaded with the Spree specific tasks, spree specific over rides are supported, such as direct s
|
214
|
+
support for OptionTypes with values
|
215
|
+
|
216
|
+
Any 'Option Types' columns can contain the OptionType to associate with the Product, plus a selection of
|
217
|
+
appropriate OptionValues to go with that Type.
|
218
|
+
|
219
|
+
For example, in a single column/row we could supply 2 OptionTypes (named, size & colour), with a selection values
|
220
|
+
(such as small, medium etc)
|
221
|
+
|
222
|
+
'Option Types'
|
223
|
+
size:small,medium,large|colour:red,white
|
224
|
+
|
225
|
+
If no such OptionType exists, e.g size, then a new one is created with the supplied name.
|
226
|
+
|
227
|
+
Next the OptionValues are also parsed, again if no such OptionValue exists, e.g small, then a new one is created with the supplied name.
|
228
|
+
|
229
|
+
Lastly a Variant is created on each OptionValue, with price and availaable dates being copied from Master.
|
230
|
+
Currently a unique SKU is created by adding an index to the master's sku.
|
231
|
+
|
232
|
+
TODO - Enable a hash of attributes to be supplied in association columns to enable more control over creation of associated objects.
|
233
|
+
|
234
|
+
### Properties
|
235
|
+
|
236
|
+
The properties to associate with this product.
|
237
|
+
Properties are for small snippets of text, shared across many products,
|
238
|
+
and are for display purposes only.
|
239
|
+
|
240
|
+
An optional display value can be supplied to supplement the displayed text.
|
241
|
+
|
242
|
+
As for all associations can contain multiple name/value sets in default form :
|
243
|
+
|
244
|
+
Property:display_value|Property:display_value
|
245
|
+
|
246
|
+
Example - No values :
|
247
|
+
manufacturer|standard
|
248
|
+
|
249
|
+
Example - Display values :
|
250
|
+
manufacturer:somebody else plc|standard:ISOBlah21
|
251
|
+
|
252
|
+
## TODO
|
253
|
+
|
254
|
+
- Add direct Image loading to Spree i.e should be able to specify just path in a column .. "/images/red-tshirt.jpg"
|
255
|
+
|
256
|
+
- Smart sorting of column processing order ....
|
257
|
+
|
258
|
+
- Does not currently ensure mandatory columns (for valid?) processed first.
|
259
|
+
|
260
|
+
## License
|
261
|
+
|
262
|
+
Copyright:: (c) Autotelik Media Ltd 2011
|
263
|
+
|
264
|
+
Author :: Tom Statter
|
265
|
+
|
266
|
+
Date :: Dec 2011
|
267
|
+
|
268
|
+
The MIT License
|
269
|
+
|
270
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
271
|
+
of this software and associated documentation files (the "Software"), to deal
|
272
|
+
in the Software without restriction, including without limitation the rights
|
273
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
274
|
+
copies of the Software, and to permit persons to whom the Software is
|
275
|
+
furnished to do so, subject to the following conditions:
|
276
|
+
|
277
|
+
The above copyright notice and this permission notice shall be included in
|
278
|
+
all copies or substantial portions of the Software.
|
279
|
+
|
280
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
281
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
282
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
283
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
284
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
285
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
286
|
+
THE SOFTWARE.
|