datashift 0.2.1 → 0.2.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.
- data/.document +5 -5
- data/LICENSE.txt +26 -26
- data/README.markdown +326 -305
- data/README.rdoc +19 -19
- data/Rakefile +86 -93
- data/VERSION +1 -1
- data/datashift.gemspec +163 -152
- data/lib/applications/jruby/jexcel_file.rb +410 -408
- data/lib/applications/jruby/word.rb +79 -79
- data/lib/datashift.rb +183 -152
- data/lib/datashift/exceptions.rb +11 -11
- data/lib/datashift/file_definitions.rb +353 -353
- data/lib/datashift/mapping_file_definitions.rb +87 -87
- data/lib/datashift/method_detail.rb +293 -275
- data/lib/datashift/method_dictionary.rb +208 -209
- data/lib/datashift/method_mapper.rb +90 -90
- data/lib/datashift/model_mapper.rb +27 -0
- data/lib/exporters/csv_exporter.rb +36 -0
- data/lib/exporters/excel_exporter.rb +116 -0
- data/lib/exporters/exporter_base.rb +15 -0
- data/lib/generators/csv_generator.rb +36 -36
- data/lib/generators/excel_generator.rb +106 -122
- data/lib/generators/generator_base.rb +13 -13
- data/lib/helpers/core_ext/to_b.rb +24 -24
- data/lib/helpers/rake_utils.rb +42 -0
- data/lib/helpers/spree_helper.rb +194 -153
- data/lib/java/poi-3.7/LICENSE +507 -507
- data/lib/java/poi-3.7/NOTICE +21 -21
- data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -115
- data/lib/loaders/csv_loader.rb +98 -98
- data/lib/loaders/excel_loader.rb +155 -155
- data/lib/loaders/loader_base.rb +420 -420
- data/lib/loaders/spreadsheet_loader.rb +136 -136
- data/lib/loaders/spree/image_loader.rb +67 -63
- data/lib/loaders/spree/product_loader.rb +289 -248
- data/lib/thor/generate_excel.thor +54 -0
- data/sandbox/app/controllers/application_controller.rb +3 -0
- data/sandbox/config/application.rb +43 -0
- data/sandbox/config/database.yml +34 -0
- data/sandbox/config/environment.rb +7 -0
- data/sandbox/config/environments/development.rb +30 -0
- data/spec/csv_loader_spec.rb +30 -30
- data/spec/datashift_spec.rb +26 -26
- data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -85
- data/spec/excel_exporter_spec.rb +78 -78
- data/spec/excel_generator_spec.rb +78 -78
- data/spec/excel_loader_spec.rb +223 -223
- data/spec/file_definitions.rb +141 -141
- data/spec/fixtures/ProjectsDefaults.yml +29 -29
- data/spec/fixtures/config/database.yml +27 -27
- data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
- data/spec/fixtures/datashift_test_models_db.sqlite +0 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -4
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -4
- data/spec/fixtures/spree/SpreeProducts.csv +4 -4
- data/spec/fixtures/spree/SpreeProducts.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsWithImages.csv +4 -4
- data/spec/fixtures/spree/SpreeZoneExample.csv +5 -5
- data/spec/fixtures/test_model_defs.rb +57 -57
- data/spec/loader_spec.rb +120 -120
- data/spec/method_dictionary_spec.rb +242 -242
- data/spec/method_mapper_spec.rb +41 -41
- data/spec/spec_helper.rb +154 -116
- data/spec/spree_exporter_spec.rb +67 -0
- data/spec/spree_generator_spec.rb +77 -64
- data/spec/spree_loader_spec.rb +363 -324
- data/spec/spree_method_mapping_spec.rb +218 -214
- data/tasks/config/seed_fu_product_template.erb +15 -15
- data/tasks/config/tidy_config.txt +12 -12
- data/tasks/{excel_generator.rake → export/excel_generator.rake} +101 -78
- data/tasks/file_tasks.rake +36 -36
- data/tasks/import/csv.rake +50 -49
- data/tasks/import/excel.rake +74 -71
- data/tasks/spree/image_load.rake +108 -108
- data/tasks/spree/product_loader.rake +43 -43
- data/tasks/word_to_seedfu.rake +166 -166
- data/test/helper.rb +18 -18
- data/test/test_interact.rb +7 -7
- metadata +16 -8
- data/datashift-0.1.0.gem +0 -0
- data/tasks/db_tasks.rake +0 -66
@@ -1,14 +1,14 @@
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
-
# Author :: Tom Statter
|
3
|
-
# Date :: Aug 2010
|
4
|
-
# License:: MIT
|
5
|
-
#
|
6
|
-
# Details:: Base class for generators, which provide serivrs to describe a Model in an external format
|
7
|
-
#
|
8
|
-
module DataShift
|
9
|
-
|
10
|
-
class GeneratorBase
|
11
|
-
|
12
|
-
end
|
13
|
-
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2010
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Base class for generators, which provide serivrs to describe a Model in an external format
|
7
|
+
#
|
8
|
+
module DataShift
|
9
|
+
|
10
|
+
class GeneratorBase
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
14
|
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
class Object
|
2
|
-
def to_b
|
3
|
-
case self
|
4
|
-
when true, false then self
|
5
|
-
when nil then false
|
6
|
-
else
|
7
|
-
to_i != 0
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class String
|
13
|
-
TRUE_REGEXP = /^(yes|true|on|t|1|\-1)$/i.freeze
|
14
|
-
FALSE_REGEXP = /^(no|false|off|f|0)$/i.freeze
|
15
|
-
|
16
|
-
def to_b
|
17
|
-
case self
|
18
|
-
when TRUE_REGEXP then true
|
19
|
-
when FALSE_REGEXP then false
|
20
|
-
else
|
21
|
-
to_i != 0
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
class Object
|
2
|
+
def to_b
|
3
|
+
case self
|
4
|
+
when true, false then self
|
5
|
+
when nil then false
|
6
|
+
else
|
7
|
+
to_i != 0
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class String
|
13
|
+
TRUE_REGEXP = /^(yes|true|on|t|1|\-1)$/i.freeze
|
14
|
+
FALSE_REGEXP = /^(no|false|off|f|0)$/i.freeze
|
15
|
+
|
16
|
+
def to_b
|
17
|
+
case self
|
18
|
+
when TRUE_REGEXP then true
|
19
|
+
when FALSE_REGEXP then false
|
20
|
+
else
|
21
|
+
to_i != 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
#
|
7
|
+
module RakeUtils
|
8
|
+
|
9
|
+
# Method to check arguments from a rake task and display help if required
|
10
|
+
#
|
11
|
+
# Expects a block which prints out the usage information
|
12
|
+
#
|
13
|
+
# task_args is expected to be of type Rake::TaskArguments
|
14
|
+
#
|
15
|
+
# NOTES: TaskArgs - bit of a weird class, has internal hash but also looks up on ENV
|
16
|
+
# So if ENV[:filter] defined, args[:filter] would return the value,
|
17
|
+
# but it would not show up in args.inspect or args.to_s or args.to_hash
|
18
|
+
#
|
19
|
+
def self.check_args( task_args, required = [] )
|
20
|
+
|
21
|
+
# Tasks that call other tasks may wish to switch off displaying help for those sub tasks
|
22
|
+
|
23
|
+
if( block_given? )
|
24
|
+
yield unless task_args && required
|
25
|
+
|
26
|
+
# Does task_args contain keys for ALL required items
|
27
|
+
if(task_args[:help] || ENV['help'])
|
28
|
+
yield
|
29
|
+
exit(-1)
|
30
|
+
end
|
31
|
+
|
32
|
+
required.each do |r|
|
33
|
+
unless(task_args.send(r))# || task_args[r.to_sym])
|
34
|
+
puts "ERROR: Missing mandatory Param [#{r}]"
|
35
|
+
yield
|
36
|
+
exit(-1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/helpers/spree_helper.rb
CHANGED
@@ -1,153 +1,194 @@
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
-
# Author :: Tom Statter
|
3
|
-
# Date :: Aug 2011
|
4
|
-
# License:: MIT
|
5
|
-
#
|
6
|
-
# Details:: Spree Helper mixing in Support for testing or loading Rails Spree e-commerce.
|
7
|
-
#
|
8
|
-
# The Spree version you want to test should be picked up from the Gemfile
|
9
|
-
#
|
10
|
-
# Since datashift gem is not a Rails app or a Spree App, provides utilities to internally
|
11
|
-
# create a Spree Database, and to load Spree components, enabling standalone testing.
|
12
|
-
#
|
13
|
-
# => Has been tested with 0.7
|
14
|
-
#
|
15
|
-
# # => TODO - Can we move to a Gemfile/bunlder
|
16
|
-
# require 'rubygems'
|
17
|
-
# gemfile = File.expand_path("<%= gemfile_path %>", __FILE__)
|
18
|
-
#
|
19
|
-
# ENV['BUNDLE_GEMFILE'] = gemfile
|
20
|
-
# require 'bundler'
|
21
|
-
# Bundler.setup
|
22
|
-
#
|
23
|
-
# => TODO - See if we can improve DB creation/migration ....
|
24
|
-
# N.B Some or all of Spree Tests may fail very first time run,
|
25
|
-
# as the database is auto generated
|
26
|
-
# =>
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Spree Helper mixing in Support for testing or loading Rails Spree e-commerce.
|
7
|
+
#
|
8
|
+
# The Spree version you want to test should be picked up from the Gemfile
|
9
|
+
#
|
10
|
+
# Since datashift gem is not a Rails app or a Spree App, provides utilities to internally
|
11
|
+
# create a Spree Database, and to load Spree components, enabling standalone testing.
|
12
|
+
#
|
13
|
+
# => Has been tested with 0.7
|
14
|
+
#
|
15
|
+
# # => TODO - Can we move to a Gemfile/bunlder
|
16
|
+
# require 'rubygems'
|
17
|
+
# gemfile = File.expand_path("<%= gemfile_path %>", __FILE__)
|
18
|
+
#
|
19
|
+
# ENV['BUNDLE_GEMFILE'] = gemfile
|
20
|
+
# require 'bundler'
|
21
|
+
# Bundler.setup
|
22
|
+
#
|
23
|
+
# => TODO - See if we can improve DB creation/migration ....
|
24
|
+
# N.B Some or all of Spree Tests may fail very first time run,
|
25
|
+
# as the database is auto generated
|
26
|
+
# =>
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
module DataShift
|
31
|
+
|
32
|
+
module SpreeHelper
|
33
|
+
|
34
|
+
|
35
|
+
def self.root
|
36
|
+
Gem.loaded_specs['spree_core'] ? Gem.loaded_specs['spree_core'].full_gem_path : ""
|
37
|
+
end
|
38
|
+
|
39
|
+
# Helpers so we can cope with both pre 1.0 and post 1.0 versions of Spree in same datashift version
|
40
|
+
|
41
|
+
def self.get_spree_class(x)
|
42
|
+
if(is_namespace_version())
|
43
|
+
ModelMapper::class_from_string("Spree::#{x}")
|
44
|
+
else
|
45
|
+
ModelMapper::class_from_string(x.to_s)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_product_class
|
50
|
+
if(is_namespace_version())
|
51
|
+
Spree::Product
|
52
|
+
else
|
53
|
+
Product
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.is_namespace_version
|
58
|
+
Gem.loaded_specs['spree'].version.version.to_f >= 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.lib_root
|
62
|
+
File.join(root, 'lib')
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.app_root
|
66
|
+
File.join(root, 'app')
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.load()
|
70
|
+
require 'spree'
|
71
|
+
require 'spree_core'
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
# Datahift isi usually included and tasks pulled in by a parent/host application.
|
76
|
+
# So here we are hacking our way around the fact that datashift is not a Rails/Spree app/engine
|
77
|
+
# so that we can ** run our specs ** directly in datashift library
|
78
|
+
# i.e without ever having to install datashift in a host application
|
79
|
+
def self.boot( database_env )
|
80
|
+
|
81
|
+
if( ! is_namespace_version )
|
82
|
+
db_connect( database_env )
|
83
|
+
@dslog.info "Booting Spree using pre 1.0.0 version"
|
84
|
+
boot_pre_1
|
85
|
+
@dslog.info "Booted Spree using pre 1.0.0 version"
|
86
|
+
else
|
87
|
+
|
88
|
+
# TODO as Spree versions moves how do we best track reqd Rails version
|
89
|
+
# parse the gemspec of the core Gemfile ?
|
90
|
+
|
91
|
+
gem('rails', '3.1.3')
|
92
|
+
|
93
|
+
db_connect( database_env, '3.1.3' )
|
94
|
+
|
95
|
+
@dslog.info "Booting Spree using post 1.0.0 version"
|
96
|
+
|
97
|
+
require 'rails/all'
|
98
|
+
|
99
|
+
Dir.chdir( File.expand_path('../../../sandbox', __FILE__) )
|
100
|
+
|
101
|
+
require 'config/environment.rb'
|
102
|
+
|
103
|
+
@dslog.info "Booted Spree using post 1.0.0 version"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.boot_pre_1
|
108
|
+
|
109
|
+
require 'rake'
|
110
|
+
require 'rubygems/package_task'
|
111
|
+
require 'thor/group'
|
112
|
+
|
113
|
+
require 'spree_core/preferences/model_hooks'
|
114
|
+
#
|
115
|
+
# Initialize preference system
|
116
|
+
ActiveRecord::Base.class_eval do
|
117
|
+
include Spree::Preferences
|
118
|
+
include Spree::Preferences::ModelHooks
|
119
|
+
end
|
120
|
+
|
121
|
+
gem 'paperclip'
|
122
|
+
gem 'nested_set'
|
123
|
+
|
124
|
+
require 'nested_set'
|
125
|
+
require 'paperclip'
|
126
|
+
require 'acts_as_list'
|
127
|
+
|
128
|
+
CollectiveIdea::Acts::NestedSet::Railtie.extend_active_record
|
129
|
+
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
130
|
+
|
131
|
+
gem 'activemerchant'
|
132
|
+
require 'active_merchant'
|
133
|
+
require 'active_merchant/billing/gateway'
|
134
|
+
|
135
|
+
ActiveRecord::Base.send(:include, ActiveMerchant::Billing)
|
136
|
+
|
137
|
+
require 'scopes'
|
138
|
+
|
139
|
+
# Not sure how Rails manages this seems lots of circular dependencies so
|
140
|
+
# keep trying stuff till no more errors
|
141
|
+
|
142
|
+
Dir[lib_root + '/*.rb'].each do |r|
|
143
|
+
begin
|
144
|
+
require r if File.file?(r)
|
145
|
+
rescue => e
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
Dir[lib_root + '/**/*.rb'].each do |r|
|
150
|
+
begin
|
151
|
+
require r if File.file?(r) && ! r.include?('testing') && ! r.include?('generators')
|
152
|
+
rescue => e
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
load_models( true )
|
157
|
+
|
158
|
+
Dir[lib_root + '/*.rb'].each do |r|
|
159
|
+
begin
|
160
|
+
require r if File.file?(r)
|
161
|
+
rescue => e
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
Dir[lib_root + '/**/*.rb'].each do |r|
|
166
|
+
begin
|
167
|
+
require r if File.file?(r) && ! r.include?('testing') && ! r.include?('generators')
|
168
|
+
rescue => e
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# require 'lib/product_filters'
|
173
|
+
|
174
|
+
load_models( true )
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.load_models( report_errors = nil )
|
179
|
+
puts 'Loading Spree models from', root
|
180
|
+
Dir[root + '/app/models/**/*.rb'].each {|r|
|
181
|
+
begin
|
182
|
+
require r if File.file?(r)
|
183
|
+
rescue => e
|
184
|
+
puts("WARNING failed to load #{r}", e.inspect) if(report_errors == true)
|
185
|
+
end
|
186
|
+
}
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.migrate_up
|
190
|
+
ActiveRecord::Migrator.up( File.join(root, 'db/migrate') )
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
end
|